MongoDB 没有保存我分配给它的 dbpath。如何保存数据库路径?

MongoDB isn't saving the dbpath that I assign to it. How can I save the dbpath?

我是这样设置我的 dbpath 的:

mongod --dbpath /Users/dylan/development/mongodb/data/db

然后它连接到数据库并运行良好。但是,一旦我退出并尝试再次启动 mongod,它就会出现此错误:

Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option

出于某种原因,它没有保存 --dbpath

最佳做法是将所有启动参数存储在 mongod.conf yaml 文件中 并每次使用 mongo --config mongodb.conf 文件或作为服务启动 mongod 进程。 示例内容:

storage:
  dbPath: /Users/dylan/development/mongodb/data/db

如果您不指定 dbPath 位置,mongod 进程从默认的 dbPath 位置(/data/db)开始,或者如果作为服务启动,dbPath 在位于 [=19 的默认配置文件中找到=] 在 /etc/mongod.conf