node.js 未找到 MongoDB 数据/数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37702957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:17:33  来源:igfitidea点击:

MongoDB data/db not found

node.jsmongodb

提问by volna

I do gave this path for data/db

我确实为 data/db 提供了这条路径

/usr/local/Cellar/mongodb/3.2.6/data/db

The following step was made in order to create a bound to mongodb folder

以下步骤是为了创建一个绑定到 mongodb 文件夹

sudo mongod --directoryperdb --dbpath /usr/local/Cellar/mongodb/3.2.6/data/db --logpath /usr/local/Cellar/mongodb/3.2.6/log/mongodb.log --logappend -rest

When initialize sudo mongod in terminal the following error appears:

在终端中初始化 sudo mongod 时出现以下错误:

2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] MongoDB starting : pid=8107 port=27017 dbpath=/data/db 64-bit host=iMac-Krystyna-2.local
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] db version v3.2.6
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2h  3 May 2016
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] allocator: system
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] modules: none
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] build environment:
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten]     distarch: x86_64
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] options: {}
2016-06-08T14:45:06.970+0200 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] dbexit:  rc: 100

Can you please explain what is wrong and maybe show some common practice in order to work correctly with MongoDB?

您能否解释一下出了什么问题,也许可以展示一些常见的做法,以便与 MongoDB 一起正常工作?

回答by Zamba

You need to create this directory as root

您需要以 root 身份创建此目录

Either you need to use sudo , e.g. sudo mkdir -p /data/db

您需要使用 sudo ,例如 sudo mkdir -p /data/db

Or you need to do su - to become superuser, and then create the directory with mkdir -p /data/db

或者你需要做 su - 成为超级用户,然后用 mkdir -p /data/db

回答by naruto_1906

You can also give this command sudo mongod --dbpath=/var/lib/mongodb. Open another terminal and run your mongod.

你也可以给出这个命令sudo mongod --dbpath=/var/lib/mongodb。打开另一个终端并运行你的mongod

回答by Alexander G.M.

It worked for me. try: sudo service mongod start

它对我有用。尝试:sudo service mongod start

回答by Aaron

In my case, an incorrect conf file caused Mongo to use default settings (i.e. using /data/dbas the storage path. Because /data/dbdoesn't exist, it complains.

在我的例子中,一个不正确的 conf 文件导致 Mongo 使用默认设置(即/data/db用作存储路径。因为/data/db不存在,它会抱怨。

Possible sources of incorrect config include:

错误配置的可能来源包括:

(1) Unquoted strings. E.g. storage.dbPath should be "some/path"(2) Incorrect bindIp. It seems an array of IPs is not supported.

(1) 未加引号的字符串。例如 storage.dbPath 应该是"some/path"(2) 不正确的 bindIp。似乎不支持 IP 数组。

So my fix was simply to use quoted strings in those places: storage: dbPath: "/some/path" net: bindIp: "127.0.0.1"

所以我的修复只是在这些地方使用带引号的字符串: storage: dbPath: "/some/path" net: bindIp: "127.0.0.1"

Note: My "/some/path"has permissions drwxr-xr-x (755) and is owned by mongodb/mongodb. And it works.

注意:我的"/some/path"权限为 drwxr-xr-x (755) 并且归 mongodb/mongodb 所有。它有效。

回答by Girdhari Agrawal

MongoDBtry to find data/db folder under root directory of your system. try to create folder under /data/db.

MongoDB尝试在系统根目录下找到 data/db 文件夹。尝试在 /data/db 下创建文件夹。