Mongod 抱怨没有 /data/db 文件夹

发布于 2024-12-12 14:45:15 字数 1681 浏览 0 评论 0原文

我今天第一次使用我的新 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”时,我确实看到了数据目录和数据库目录。但在 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

谢谢大家!

I am using my new mac for the first time today. I am following the get started guide on the mongodb.org up until the step where one creates the /data/db directory. btw, I used the homebrew route.

So I open a terminal, and I think I am at what you called the Home Directory, for when I do "ls", I see folders of Desktop Application Movies Music Pictures Documents and Library.

So I did a

mkdir -p /data/db

first, it says permission denied. I kept trying different things for half and hour and finally :

mkdir -p data/db

worked. and when I "ls", a directory of data and nested in it a db folder do exist.

then I fire up mongod and it complains about not finding data/db

Have I done something wrong?

Now I have done the

sudo mkdir -p /data/db

and when I do a "ls" I do see the data dir and the db dir. inside the db dir though, there is absolutely nothing in it and when I now run 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

EDIT
Getting error message for

sudo chown mongod:mongod /data/db

chown: mongod: Invalid argument

Thanks, everyone!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(29

美羊羊 2024-12-19 14:45:17

在根目录中创建目录

sudo mkdir -p /data/db

现在更改所有者

sudo chown -R $USER /data

一切顺利!

mongod

而不是使用 sudo mongod,你不需要输入所有的密码,但是对于真正的项目你应该使用sudo mongod,不要给普通用户权限!

Create directory in the Root

sudo mkdir -p /data/db

Now change the Owner

sudo chown -R $USER /data

You're good to go!

mongod

instead of using sudo mongod, you don't need to put everythime password, but for the real project you should use sudo mongod, don't give permission to normal user!

不忘初心 2024-12-19 14:45:17

您需要在根目录中创建 /data/db ...这是一个名为 /data/ 的目录(即 /< /strong>)和其中名为 /db/ 的子文件夹...

您收到权限错误,因为您需要使用 sudo 在根目录中创建一个目录MacOS 中,sudo 允许您以管理员身份运行命令。

所以,运行这个......

$ sudo mkdir -p /data/db

这将提示您输入密码,它与您用于更改系统设置的密码相同(当您尝试更改 ecample 的系统偏好设置中的内容时打开的小对话框),并且可能与你用来登录。

You need to create /data/db ... that is a directory called /data/ in your root (i.e. /) and subfolder in there called /db/ ...

You're getting permission errors becuase you need to use sudo to create a direcotry in your root dir in MacOS, sudo lets you run commands as an administrator.

So, run this instead ...

$ sudo mkdir -p /data/db

This will prompt you for a password, it's the same password you use to change system settings (that little dialog that opens when you try and change things in System Preferences for ecample), and likely the same as you use to login.

掌心的温暖 2024-12-19 14:45:17

Mongodb 运行时 mongod 会在设备根文件夹中查找 ~/data/db 文件夹作为 db 的路径。

我通过运行 mkdir ~/data 创建一个 ~/data 文件夹解决了这个问题。

在根文件夹中输入 ls 检查数据文件夹是否存在。 。然后导航到数据文件夹并仔细检查 pwd 应该为您提供 /Users/username/data

然后运行此命令来创建 mongodb 数据库路径
sudo mongod --dbpath=/Users/username/data

当我运行 mongod 时,这对我来说是有效的

Mongodb when running mongod looks for ~/data/db folder in as a path for db in the root folder of your device.

I solved it by creating a ~/data folder by running mkdir ~/data

In the root folder check if data folder is there by typing ls. Then navigate to the data folder and double check pwd should give you /Users/username/data

Then run this command to create a mongodb db path
sudo mongod --dbpath=/Users/username/data

This did it for me and when I ran mongod

香草可樂 2024-12-19 14:45:17

简单说明一下:

如果您尝试在不更改权限的情况下运行 mongod,则 /data/db 目录中可能会有一个 mongod.lock 文件(以及一些其他文件)。即使您更改了 /data/db 目录的权限以授予 $USER 访问权限,您仍将继续收到“无法创建/打开锁定文件:/data/db/mongod.lock errno:13 权限被拒绝”的消息“ 错误。运行 ls -al /data/db,您可能会看到各个文件的权限仍然设置为 root 用户,而不是您的 $USER。您应该删除 mongod.lock 文件以及其他文件。然后,当您再次运行 mongod 时,一切都应该正常,并且您可以通过再次运行 ls -al 来验证文件权限是否与目录权限匹配。

Just a quick note:

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.

思慕 2024-12-19 14:45:17

当我尝试启动 mongodb 时,不断收到以下错误。

"shutting down with code:100" 

我使用以下命令:

./mongod --dbpath=~/mongo-data

对我来说,修复是我不需要“=”符号,这导致了错误。所以我

./mongod --dbpath ~/mongo-data

只是想把它扔掉,因为该错误绝不表明这就是问题所在。我几乎删除了 ~/mongo-data 目录的内容,看看是否有帮助。很高兴我记得 cli 参数有时不使用“=”符号。

I kept getting the following error when I tried to start mongodb.

"shutting down with code:100" 

I was using the following command:

./mongod --dbpath=~/mongo-data

The fix for me was that I didn't need the "=" sign and this was causing the error. So I did

./mongod --dbpath ~/mongo-data

Just wanted to throw this out there because the error in no way specifies that this is the problem. I almost removed the contents of the ~/mongo-data directory to see if that helped. Glad I remembered that cli args sometimes do not use the "=" sign.

与之呼应 2024-12-19 14:45:17

到目前为止,我还曾经认为我们需要创建 /data/db 文件夹来启动 mongod 命令。

但最近我尝试使用服务命令启动 mongod,它对我有用,并且不需要创建 /data/db 目录。

service mongod start

要检查 mongod 的状态,您可以运行以下命令。

service mongod status

Till this date I also used to think that we need to create that /data/db folder for starting mongod command.

But recently I tried to start mongod with service command and it worked for me and there was no need to create /data/db directory.

service mongod start

As to check the status of mongod you can run the following command.

service mongod status
日记撕了你也走了 2024-12-19 14:45:17

这个解决方案解决了我的问题

  1. 将目录创建为

    sudo mkdir -p /data/db

  2. 这将创建一个名为 db 的目录,然后尝试使用命令启动

    sudo mongod

启动如果您在启动 mongod 时遇到另一个错误或问题,您可能会发现问题为

无法设置侦听器:SocketException:地址已在使用中
如果您发现另一个错误,则必须通过在终端中键入以下内容来终止 mongod 正在运行的进程

ps ax | grep mongod
sudo kill ps_number

,并找到 mongod 运行端口并终止该进程。
另一种方法是在启动 mongod 时创建一个特定的端口

sudo mongod --port 27018

This solution solves my problem

  1. Make a directory as

    sudo mkdir -p /data/db

  2. That will make a directory named as db and than try to start with commands

    sudo mongod

If you get another error or problem with starting mongod, You may find problem as

Failed to set up listener: SocketException: Address already in use
If you find that another error than you have to kill the running process of mongod by typing to terminal as

ps ax | grep mongod
sudo kill ps_number

and find the mongod running port and kill the process.
Another way is to make a specefic port when starting mongod as

sudo mongod --port 27018
隐诗 2024-12-19 14:45:17

从 MongoDB 4.4 开始,MongoDB 数据库工具现在与 MongoDB 服务器分开发布。

您需要下载: https://www.mongodb.com/try /download/database-tools?tck=docs_databasetools

然后将所有文件复制到 /usr/bin
并且所有命令行都将可用。

Starting with MongoDB 4.4, the MongoDB Database Tools are now released separately from the MongoDB Server.

You need to download : https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools

then you copy all the files into /usr/bin
and all the command lines will be available.

秋千易 2024-12-19 14:45:17

在终端上输入“id”以查看您可以提供的可用用户 ID,
然后只需输入

“sudo chown -R idname /data/db”

这对我来说很有效!
希望这能解决您的问题。

Type "id" on terminal to see the available user ids you can give,
Then simply type

"sudo chown -R idname /data/db"

This worked out for me!
Hope this resolves your issue.

允世 2024-12-19 14:45:17

在 MongoDB 的最新版本中,我有 3.2.10,它默认存储到

/var/lib/mongodb

In more current versions of MongoDB, I have 3.2.10, it is stored be default into

/var/lib/mongodb

横笛休吹塞上声 2024-12-19 14:45:17

蒂洛的答案对我有用,直到这:

sudo chown -R 126:135 /data/db 

我必须使用:

sudo chown -R $USER /data/db

Tilo has the answer that worked for me up until THIS:

sudo chown -R 126:135 /data/db 

I had to use:

sudo chown -R $USER /data/db
梦中的蝴蝶 2024-12-19 14:45:17

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

1)暂时离开你的 mongo 安装
2)回来后服务器没有运行
3) 尝试启动它,但这次不要使用 sudo
4) mongo 找不到 data/db/ 因为现在它在用户主目录中查找而不是 su 主目录 是

的,这确实很愚蠢,但如果您已经在系统上一段时间了,它可能会让您出错。

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

There is a really dumb way to create this problem, which I have pioneered:

1) leave your mongo install for a while
2) come back and the server is not running
3) attempt to start it, but don't use sudo this time
4) mongo can't find data/db/ because now its looking in the user home dir instead of su home dir

Yes, it is really dumb but if its been a while since you were on the system it can trip you up.

Short answer: make sure you run mongo with the same implied home directory

霓裳挽歌倾城醉 2024-12-19 14:45:17

确保您的 Linux 实例上有足够的磁盘空间。

Make sure there's enough Disk Space on your Linux instance.

冷情 2024-12-19 14:45:17

如果您收到命令的mkdir: /data: Read-only file system
sudo mkdir -p /data/db 您可以像这样创建目录:

mkdir -p ~/data/db。请注意~标志。

之后 mongod --dbpath ~/data/db

If you are getting mkdir: /data: Read-only file system for command
sudo mkdir -p /data/db you may create the directory like this:

mkdir -p ~/data/db. notice the ~ sign please.

After that mongod --dbpath ~/data/db

禾厶谷欠 2024-12-19 14:45:16

您在错误的位置创建了目录

/data/db 意味着它直接位于“/”根目录下,而您创建的“data/db”(没有前导 /)可能只是在另一个目录中,例如“/root”主目录。

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

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

或者您需要这样做su - 成为超级用户,然后使用 mkdir -p /data/db 创建目录


注意:

MongoDB 还有一个选项,您可以在另一个位置创建数据目录,但这通常不是一个好主意,因为它只是使数据库恢复等事情稍微复杂一些,因为您始终必须手动指定数据库路径。我不建议这样做。


编辑:

您收到的错误消息是“无法创建/打开锁定文件:/data/db/mongod.lock errno:13 权限被拒绝”。您创建的目录似乎没有正确的权限和所有权 -
它需要由运行 MongoDB 进程的用户可写。

要查看“/data/db/”目录的权限和所有权,请执行以下操作:
(这是权限和所有权的样子)

$ ls -ld /data/db/
drwxr-xr-x 4 mongod mongod 4096 Oct 26 10:31 /data/db/

左侧“drwxr-xr-x”显示用户、组和其他人的权限。
'mongod mongod' 显示谁拥有该目录,以及该目录属于哪个组。
在这种情况下,两者都称为“mongod”。

如果您的“/data/db”目录没有上述权限和所有权,请执行以下操作

首先检查您的 mongo 用户拥有哪些用户和组:

# grep mongo /etc/passwd
mongod:x:498:496:mongod:/var/lib/mongo:/bin/false

您应该在 /etc 中有一个 mongod 条目/passwd ,因为它是一个守护进程。

sudo chmod 0755 /data/db
sudo chown -R 498:496 /data/db    # using the user-id , group-id

您还可以使用用户名和组名,如下所示:
(它们可以在 /etc/passwd 和 /etc/group 中找到)

sudo chown -R mongod:mongod /data/db 

应该可以使其工作。

在下面的评论中,有些人使用了这个:

sudo chown -R `id -u` /data/db
sudo chmod -R go+w /data/db

sudo chown -R $USER /data/db 
sudo chmod -R go+w /data/db

缺点是 $USER 是一个具有登录 shell 的帐户。
出于安全原因,理想情况下守护进程不应有 shell,这就是为什么您在上面的密码文件的 grep 中看到 /bin/false 的原因。

检查此处以更好地理解目录权限的含义:

http://www.perlfect.com/articles /chmod.shtml

也许还可以查看您可以通过 Google 找到的教程之一:“UNIX 初学者”

You created the directory in the wrong place

/data/db means that it's directly under the '/' root directory, whereas you created 'data/db' (without the leading /) probably just inside another directory, such as the '/root' homedirectory.

You need to create this directory as root

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

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


Note:

MongoDB also has an option where you can create the data directory in another location, but that's generally not a good idea, because it just slightly complicates things such as DB recovery, because you always have to specify the db-path manually. I wouldn't recommend doing that.


Edit:

the error message you're getting is "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied". The directory you created doesn't seem to have the correct permissions and ownership --
it needs to be writable by the user who runs the MongoDB process.

To see the permissions and ownership of the '/data/db/' directory, do this:
(this is what the permissions and ownership should look like)

$ ls -ld /data/db/
drwxr-xr-x 4 mongod mongod 4096 Oct 26 10:31 /data/db/

The left side 'drwxr-xr-x' shows the permissions for the User, Group, and Others.
'mongod mongod' shows who owns the directory, and which group that directory belongs to.
Both are called 'mongod' in this case.

If your '/data/db' directory doesn't have the permissions and ownership above, do this:

First check what user and group your mongo user has:

# grep mongo /etc/passwd
mongod:x:498:496:mongod:/var/lib/mongo:/bin/false

You should have an entry for mongod in /etc/passwd , as it's a daemon.

sudo chmod 0755 /data/db
sudo chown -R 498:496 /data/db    # using the user-id , group-id

You can also use the user-name and group-name, as follows:
(they can be found in /etc/passwd and /etc/group )

sudo chown -R mongod:mongod /data/db 

that should make it work..

In the comments below, some people used this:

sudo chown -R `id -u` /data/db
sudo chmod -R go+w /data/db

or

sudo chown -R $USER /data/db 
sudo chmod -R go+w /data/db

The disadvantage is that $USER is an account which has a login shell.
Daemons should ideally not have a shell for security reasons, that's why you see /bin/false in the grep of the password file above.

Check here to better understand the meaning of the directory permissions:

http://www.perlfect.com/articles/chmod.shtml

Maybe also check out one of the tutorials you can find via Google: "UNIX for beginners"

情绪 2024-12-19 14:45:16

遇到与 Nik 相同的错误后

chown:id -u:参数无效

我发现这显然是由于使用了错误类型的引号而发生的(应该是反引号Ubuntu 论坛

相反,我只是使用

sudo chown $USER /data/db

作为替代方案,现在 mongod 拥有它所需的权限。

After getting the same error as Nik

chown: id -u: Invalid argument

I found out this apparently occurred from using the wrong type of quotation marks (should have been backquotes) Ubuntu Forums

Instead I just used

sudo chown $USER /data/db

as an alternative and now mongod has the permissions it needs.

扭转时空 2024-12-19 14:45:16

这对我有用,在评论中找到:

sudo chown -R $USER /data/db

This works for me, found in comments:

sudo chown -R $USER /data/db
許願樹丅啲祈禱 2024-12-19 14:45:16

创建文件夹。

sudo mkdir -p /data/db/

授予自己对该文件夹的权限。

sudo chown `id -u` /data/db

然后您就可以在没有 sudo 的情况下运行 mongod。适用于 OSX Yosemite

Create the folder.

sudo mkdir -p /data/db/

Give yourself permission to the folder.

sudo chown `id -u` /data/db

Then you can run mongod without sudo. Works on OSX Yosemite

三生池水覆流年 2024-12-19 14:45:16

为了修复 OS X 上的错误,我重新启动并停止了该服务:
<代码>
$brew服务重启mongodb
$brew 服务停止 mongodb

然后我运行mongod --config /usr/local/etc/mongod.conf,问题就消失了。

该错误似乎是在升级 mongodb homebrew 软件包后出现的。

To fix that error on OS X, I restarted and stopped the service:

$ brew services restart mongodb
$ brew services stop mongodb

Then I ran mongod --config /usr/local/etc/mongod.conf, and the problem was gone.

The error seemed to arise after upgrading the mongodb homebrew package.

留蓝 2024-12-19 14:45:16

如果您在不带参数的情况下运行 mongo,则假定您在生产计算机上运行,​​因此它使用默认位置。

使用您自己的数据库(开发或只是一个不同的数据库):

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

If you run mongo without arguments it's assume you are running on the production machine so it's use the default locations.

for using your own database (dev or just a different one) :

./bin/mongod --dbpath ~/data/db
萤火眠眠 2024-12-19 14:45:16

在 Mac 上通过 brew 安装,其中 YOUR_USER_NAME 和 staff 是组

sudo mkdir -p /data/db
sudo chmod +x+r+w /data/db/
sudo touch /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db
sudo chmod +x+r+w /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db/mongod.lock

Installing through brew on Mac where YOUR_USER_NAME and staff is the group

sudo mkdir -p /data/db
sudo chmod +x+r+w /data/db/
sudo touch /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db
sudo chmod +x+r+w /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db/mongod.lock
别理我 2024-12-19 14:45:16

如果您使用 Mac 并通过 Homebrew 运行 Catalina 和安装的 Mongodb,您只需输入此命令即可启动。

brew services start mongodb-community

If you are using Mac and running Catalina and Installed Mongodb via Homebrew what you have to do to start is just type this command and you are good to go.

brew services start mongodb-community
我很坚强 2024-12-19 14:45:16

我只是想在这里指出,如果您尝试此操作并遇到 mkdir: /data/db: Read-only file system,请参阅此评论,这对我有帮助:https://stackoverflow.com/a/58895373

这样,如果有人在这个答案上并执行 Control F 为“只读”,他们就会看到这个

I just wanted to point out here that if you try this and you run into mkdir: /data/db: Read-only file system, please see this comment, which helped me: https://stackoverflow.com/a/58895373.

That way if anyone is on this answer and does Control F for "read only" they will see this

指尖上的星空 2024-12-19 14:45:16

MongoDB 的 dbPath 文件夹可能会令人困惑。

当您在没有 dbpath 的情况下运行 mongod 时,默认路径为 /data/db

但是,当您将其作为服务启动时,例如 systemctl启动 mongod 然后它会读取配置文件,通常是 /etc/mongod.cfg ,在此配置文件中,默认值为

PlatformPackage ManagerDefault storage.dbPath
RHEL / CentOS和 Amazonyum/var/lib/mongo
SUSEzypper/var/lib/mongo
Ubuntu 和 Debianapt/var/lib/mongodb
macOSbrew/usr/local/var/mongodb

因此,您的 MongoDB 会意外地尝试访问不同的数据文件夹,具体取决于您启动服务的方式。

MongoDB can be confusing regarding the dbPath folder.

When you run mongod without dbpath then the default path is /data/db

However when you start it as a service, e.g. systemctl start mongod then it reads on configuration file, typially /etc/mongod.cfg and in this config file the defaults are

PlatformPackage ManagerDefault storage.dbPath
RHEL / CentOS and Amazonyum/var/lib/mongo
SUSEzypper/var/lib/mongo
Ubuntu and Debianapt/var/lib/mongodb
macOSbrew/usr/local/var/mongodb

So, by accident your MongoDB tries to access different data folders depending on how you start the service.

浅笑依然 2024-12-19 14:45:16

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

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

所以完整的命令是:

$ sudo mkdir -p /data/db

Your command will have created the directory structure in the current folder, not the root directory of your computer (which is what the missing / is).

The first command was right, but because you are trying to create a folder in /, which is a protected directory, you need to prefix it with sudo, which is short for "superuser do". You'll then be asked for your password.

So the full command would be:

$ sudo mkdir -p /data/db
浮生未歇 2024-12-19 14:45:16

我在现有的 Mongodb 设置中遇到了这个问题。我仍然不确定为什么会发生这种情况,但由于某种原因 Mongod 进程找不到 mongod.config 文件。
因为它找不到配置文件,所以它尝试在 /data/db(一个不存在的文件夹)中查找数据库文件。
但是,配置文件仍然可用,因此我确保进程具有配置文件的权限,并使用 --config 标志运行 mongod 进程,如下所示:

mongod --config /etc/mongod.conf

在配置文件本身中,我有这样的设置:

storage:
  dbPath: /var/lib/mongodb

这就是进程的方式可以再次找到真正的数据库文件夹。

I had this problem with an existing Mongodb setup. I'm still not sure why it happened, but for some reason the Mongod process couldn't find the mongod.config file.
Because it could not find the config file it tried to find the DB files in /data/db, a folder that didn't exist.
However, the config file was still available so I made sure the process has permissions to the config file and run the mongod process with the --config flag as follows:

mongod --config /etc/mongod.conf

In the config file itself I had this setting:

storage:
  dbPath: /var/lib/mongodb

And this is how the process could find the real DB folder again.

假面具 2024-12-19 14:45:16

brew install mongodb

于 2018 年 2 月 1 日完成,这给了我 mongodb 版本 3.6.2。

在上面orluke的回答的提示下,我尝试了一下

$ brew services restart mongodb

,一切都变得栩栩如生。我的 mongoose.createConnection() 调用做了我想要的事情。社区版本的 GUI MongoDB Compass 将进行连接。我使用 Compass 查看 local.startup_log 集合。其中有一个文档,我刚刚启动 mongoDB 服务的日志,并且

cmdLine:Object
    config:"/usr/local/etc/mongod.conf"

确实有这样一个文件:

$ more /usr/local/etc/mongod.conf
systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1

并且有一个 /usr/local/var/mongodb 目录,其中有很多晦涩的文件。现在安装似乎就是这样。

我不确定 brew services restart 是否将服务设置为运行登录时。所以我这样做了

brew services stop mongodb
brew services start mongodb

,并希望在重新启动后再次启动它。确实,它确实做到了。事实上,现在,我认为初始安装后正确的做法是

brew services start mongodb

启动服务并在重新启动后重新启动它。

I did

brew install mongodb

on 2018-02-01 and that gave me mongodb version 3.6.2.

Prompted by the answer from orluke above, I tried just

$ brew services restart mongodb

and everything sprang into life. My mongoose.createConnection() call did what I wanted. The GUI MongoDB Compass, the community version, would connect. I used Compass to look at the local.startup_log collection. That had one document in, the log of me just starting the mongoDB service, and that had

cmdLine:Object
    config:"/usr/local/etc/mongod.conf"

and indeed there was such a file:

$ more /usr/local/etc/mongod.conf
systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1

and there was a /usr/local/var/mongodb directory with lots of obscure files. So that seems to be how the installation works now.

I'm not sure if brew services restart sets the service to run at login. So I did

brew services stop mongodb
brew services start mongodb

and hoped that starts it again after reboot. And, indeed, it did. In fact, now, I think the right thing to do after the initial installation is

brew services start mongodb

and that should start the service and restart it after reboot.

终遇你 2024-12-19 14:45:16

您正在尝试创建一个没有 root 访问权限的目录。

为了测试 mongodb,我只使用用户目录中的一个目录,例如:

cd
mkdir -p temp/
mongod --dbpath .

这将从当前工作目录中的 temp/ 中创建一个 mongo 数据库

You're trying to create a directory you don't have root access to.

For testing mongodb, I just use a directory from my user directory like:

cd
mkdir -p temp/
mongod --dbpath .

This will make a mongo database in temp/ from your current working directory

清风夜微凉 2024-12-19 14:45:16

我通过使用窗口管理器创建 /data/db 文件夹解决了这个完全相同的问题。我首先尝试通过终端执行此操作,为了在根目录中创建文件夹,我必须使用 sudo。

我刚刚使用 Finder 进入根目录,并使用“新文件夹”创建了一个新文件夹。完全适合我。

注意:我使用的是 OSX。

I got over this exact same problem by creating the /data/db folders with my window manager. I tried doing it though the terminal at first, and in order to create a folder in the root directory, I had to use sudo.

I just went to the root directory using Finder and created a new folder using 'New Folder'. Totally worked for me.

Note: I'm using OSX.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文