在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)  HTML/ mongodb起步掉坑,求拉

mongodb起步掉坑,求拉

mongodb 版本:4.0.1
node.js 版本:9.4.0
我遇到2個(gè)問(wèn)題:

第一,我配置的環(huán)境變量不起作用,請(qǐng)問(wèn)我哪里配錯(cuò)了?

我看的這個(gè)文檔
https://docs.mongodb.com/manu...
我在/etc/profile 里寫(xiě)的配置

  1 # 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

按照文檔里說(shuō)的 我也在~/.bashrc里寫(xiě)了

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

重啟系統(tǒng),依然找不到mongod

command not found: mongod

我只能通過(guò)bin目錄下運(yùn)行:

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

而且不指定dbpath他還找不到默認(rèn)的路徑

第二個(gè)問(wèn)題 關(guān)于nodejs鏈接數(shù)據(jù)庫(kù)

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('數(shù)據(jù)庫(kù)鏈接失??!'.red);
        return;
    }

    console.log('數(shù)據(jù)庫(kù)鏈接成功!'.green);
    db.close();
});

按理說(shuō)控制臺(tái)應(yīng)該會(huì)打印出 失敗或者成功,但是啥都木有,那就是這個(gè)方法都沒(méi)有進(jìn)來(lái)。但是啟動(dòng)的mongodb控制臺(tái)又告訴我一個(gè)成功的鏈接

2018-08-06T16:45:30.385+0800 I NETWORK  [listener] connection accepted from 127.0.0.1:50537 #1 (1 connection now open)
回答
編輯回答
空白格

問(wèn)題一解決了
1.找不到默認(rèn)路徑,經(jīng)過(guò)查看跟目錄創(chuàng)建錯(cuò)誤,db寫(xiě)成了bd(尷尬)
2.全局環(huán)境變量,我修改過(guò)以下文件
/etc/profile
/etc/paths
~/.bash_profile
~/.profile
~/.bashrc

最后只有在/etc/paths中添加路徑后在使用source后生效

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

生效

但是不知道為什么在其他文件里寫(xiě)“export PATH=<mongodb-install-directory>/bin:$PATH”不管用呢?

問(wèn)題2未解決

2017年4月16日 12:20