今天我第一次用我的新mac电脑。我遵循mongodb.org上的入门指南,直到创建/data/db目录的步骤。顺便说一句,我用的是自制路线。

所以我打开一个终端,我认为我在你所谓的主目录,因为当我按“ls”时,我看到桌面应用程序、电影、音乐、图片、文档和库的文件夹。

所以我做了一个

mkdir -p /data/db

首先,它说许可被拒绝。我不停地尝试了半个小时,最后:

mkdir -p data/db

工作。当我“ls”,一个目录的数据和嵌套在其中的db文件夹确实存在。

然后我启动mongod,它抱怨找不到data/db

我做错什么了吗?

现在我已经完成了

sudo mkdir -p /data/db

当我执行“ls”时,我确实看到了data dir和db dir。在db目录下,什么都没有,当我运行mongod

Sun Oct 30 19:35:19 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Sun Oct 30 19:35:19 dbexit: 
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close listening sockets...
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to flush diaglog...
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close sockets...
Sun Oct 30 19:35:19 [initandlisten] shutdown: waiting for fs preallocator...
Sun Oct 30 19:35:19 [initandlisten] shutdown: lock for final commit...
Sun Oct 30 19:35:19 [initandlisten] shutdown: final commit...
Sun Oct 30 19:35:19 [initandlisten] shutdown: closing all files...
Sun Oct 30 19:35:19 [initandlisten] closeAllFiles() finished
Sun Oct 30 19:35:19 [initandlisten] shutdown: removing fs lock...
Sun Oct 30 19:35:19 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Sun Oct 30 19:35:19 dbexit: really exiting now

编辑 获取错误消息

sudo chown mongod:mongod /data/db

chown: mongod: Invalid argument

谢谢,大家好!


当前回答

在(重新)安装工具包后,我在一台Windows 10设备上得到了类似的错误;

initAndListen: NonExistentPath: Data目录C:\ Data \db\ not found。,终止

解决方案 类似于linux系统的解释:简单地创建文件夹就足以启动mongo .exe (mongoDB服务器)。

我想我可以把它留给那些在Windows设备上使用相同搜索词的人。

其他回答

在当前版本的MongoDB中,我有3.2.10,它被默认存储到

/var/lib/mongodb

您的命令将在当前文件夹中创建目录结构,而不是计算机的根目录(即缺少的/)。

第一个命令是正确的,但是因为您试图在/目录下创建一个文件夹,这是一个受保护的目录,所以您需要在它前面加上sudo,这是“超级用户do”的缩写。然后你会被要求输入密码。

所以完整的命令是:

$ sudo mkdir -p /data/db

简单说明一下:

If you tried running mongod without changing the permissions first, you'll likely have a mongod.lock file (and some other files) in the /data/db directory. Even after you change the permissions for the /data/db directory to give access to your $USER, you'll continue to get the "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied" error. Run ls -al /data/db and you'll probably see that the permissions for the individual files are still set to root for user, not to your $USER. You should remove the mongod.lock file, and the others as well. Then when you run mongod again, everything should work, and you can verify that the file permissions match the directory permissions by running ls -al again.

有一个非常愚蠢的方法来制造这个问题,这是我首创的:

1)让你的mongo安装一段时间 2)返回时服务器没有运行 3)尝试启动,但这次不要使用sudo 4) mongo找不到data/db/,因为现在它在用户的home目录而不是su home目录

是的,这真的很愚蠢,但如果你已经在系统上一段时间了,它可以绊倒你。

简单的回答:确保您使用相同的隐含主目录运行mongo

创建文件夹。

sudo mkdir -p /data/db/

给自己访问该文件夹的权限。

sudo chown `id -u` /data/db

然后你就可以不用sudo运行mongod了。工作在OSX优胜美地