Mongodb starts to fall into a trap, please pull.

mongodb version: 4.0.1
node.js version: 9.4.0
I encountered two problems:

first of all, the environment variable I configured doesn"t work. What"s wrong with me?

the document I read
https://docs.mongodb.com/manu.
the configuration I wrote in / etc/profile

  1 -sharp System-wide .profile for sh(1)
  2
  3 if [ -x /usr/libexec/path_helper ]; then
  4     eval `/usr/libexec/path_helper -s`
  5 fi
  6
  7 if [ "${BASH-no}" != "no" ]; then
  8     [ -r /etc/bashrc ] && . /etc/bashrc
  9 fi
 10
 11 export PATH=/Users/name/mongodb/bin:$PATH

according to what is said in the document, I also wrote

in ~ / .bashrc.
  1
  2 -sharp System-wide .profile for sh(1)
  3
  4 if [ -x /usr/libexec/path_helper ]; then
  5
  6 export PATH=/Users/name/mongodb/bin:$PATH

restart the system, still can"t find mongod

command not found: mongod

I can only run it through the bin directory:

sudo ./mongod --dbpath ~/data/db

and without specifying dbpath, he can"t find the default path

second question about nodejs linked databases

let express = require("express");
let colors = require("colors");
let app = express();
let bodyParser = require("body-parser");
let mongoClient = require("mongodb").MongoClient;
let url = "mongodb://localhost:27017/adFactory";

mongoClient.connect(url, function (err, db) {
    if (err) {
        console.log("".red);
        return;
    }

    console.log("".green);
    db.close();
});

the console is supposed to print failure or success, but there is nothing, that is, this method does not come in. But the mongodb console that started told me a successful link

2018-08-06T16:45:30.385+0800 I NETWORK  [listener] connection accepted from 127.0.0.1:50537 -sharp1 (1 connection now open)
Apr.03,2021

Once the

problem is solved
1. Can not find the default path, after checking and directory creation error, db was written as bd (embarrassing)
2. Global environment variable, I have modified the following file
/ etc/profile
/ etc/paths
~ / .bash_profile
~ / .profile
~ / .bashrc

in the end, it takes effect only after adding a path to / etc/paths and after using source

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Users/name/mongodb/bin
source paths

take effect

but I don't know why writing "export PATH= < mongodb-install-directory > / bin:$PATH" in other files doesn't work?

problem 2 is not solved

Menu