gpt4 book ai didi

mongodb - 如何设置 mongod --dbpath

转载 作者:IT老高 更新时间:2023-10-28 13:05:50 32 4
gpt4 key购买 nike

对 mongodb 和一般数据库来说非常新。每当我运行 mongo 时,我都会收到此错误消息:​​​​

MongoDB shell version: 2.4.9
connecting to: test
Thu Jan 30 13:03:33.170 Error: couldn't connect to server 127.0.0.1:27017
at src/mongo/shell/mongo.js:145
exception: connect failed

运行 mongod 我看到了这个:

Thu Jan 30 13:13:36.588 [initandlisten] MongoDB starting : pid=29408 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Kimis-MacBook-Air-2.local
Thu Jan 30 13:13:36.588 [initandlisten]
Thu Jan 30 13:13:36.588 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jan 30 13:13:36.588 [initandlisten] db version v2.4.9
Thu Jan 30 13:13:36.588 [initandlisten] git version: nogitversion
Thu Jan 30 13:13:36.588 [initandlisten] build info: Darwin minilionvm.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jan 30 13:13:36.588 [initandlisten] allocator: tcmalloc
Thu Jan 30 13:13:36.588 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb" }
Thu Jan 30 13:13:36.591 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Thu Jan 30 13:13:36.591 [initandlisten] recover begin
Thu Jan 30 13:13:36.591 [initandlisten] recover lsn: 108155770
Thu Jan 30 13:13:36.591 [initandlisten] recover /usr/local/var/mongodb/journal/j._0
Thu Jan 30 13:13:36.591 [initandlisten] journal file version number mismatch got:4147 expected:4149. if you have just upgraded, recover with old version of mongod, terminate cleanly, then upgrade.
Thu Jan 30 13:13:36.592 [initandlisten] dbexception during recovery: 13536 journal version number mismatch 16711
Thu Jan 30 13:13:36.592 [initandlisten] exception in initAndListen: 13536 journal version number mismatch 16711, terminating
Thu Jan 30 13:13:36.592 dbexit:
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close listening sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to flush diaglog...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close sockets...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: lock for final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: final commit...
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: closing all files...
Thu Jan 30 13:13:36.592 [initandlisten] closeAllFiles() finished
Thu Jan 30 13:13:36.592 [initandlisten] shutdown: removing fs lock...
Thu Jan 30 13:13:36.592 dbexit: really exiting now

当我手动将我的 mongo dpath 设置为 mongod --dbpath/data/db (应该是安装时的默认值)并让它在终端中运行时,一切运行正常。但是一旦我关闭它,一切都会再次中断。我的问题是:

  1. 为什么我的 dbpath 设置为 /usr/local/var/mongodb
  2. 如何解决此错误,以便 mongo 在我的机器上运行?

我假设我需要将 dbpath 永久设置为 /data/db 或重新配置一些东西,以便它与 dbpath 一起工作为 /usr/local/var/mongodb

我对 unix 命令也相当陌生,因此不完全确定如何修复此错误。

感谢您的任何建议!

所以,我阅读了 mongodb 文档:

“除非指定,否则 mongod 将在默认的 /data/db 目录中查找数据文件。(Windows 系统使用\data\db 目录。)如果您使用包管理系统安装。检查你的包提供的 /etc/mongodb.conf 文件以查看 dbpath 的配置。"

当我查看 /etc/ 中的文件时,没有 mongodb.conf 文件...但是,我确实看到了 /usr/local/etc/mongod.conf...所以如果我理解正确,我应该创建一个名为 /etc/mongodb.conf 的文件并将 dbpath 设置为 /data/db.

我是否也需要删除 /usr/local/ 中的内容?

我认为这与我的 PATH 的设置方式有关...有人可以向我解释如何在 unix 中解决这个问题,这样我就不会遇到这个问题了吗?

再次感谢!

最佳答案

只在 Mac 上试过这个:

  • 在应用的根文件夹中创建数据目录
  • cd 到您安装 mongo 目录时放置的任何位置
  • 运行这个命令:

    mongod --dbpath ~/path/to/your/app/data

你应该很高兴!

关于mongodb - 如何设置 mongod --dbpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21448268/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com