【问题标题】:How to specify the path to config file in mongodb如何在mongodb中指定配置文件的路径
【发布时间】:2018-12-10 04:32:51
【问题描述】:

在配置文件中我有:

systemLog:
    destination: file
    logAppend: true
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db
    journal:
        enabled: true
replication:
   replSetName: "rs0"
net:
   bindIp: 127.0.0.1
   port: 27017
security:
     authorization: enabled

我正在尝试使用mongod 进程进行连接,例如documentation

C:\Program Files\MongoDB\Server\3.6\bin> mongod --auth --dbpath /data/db --config C:\Program Files\MongoDB\Server\3.6\mongod.cfg

得到:

读取配置文件时出错:没有这样的文件或目录
尝试 'C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe --help' 了解更多信息

然后尝试使用引号

C:\Program Files\MongoDB\Server\3.6\bin> mongod --auth --dbpath /data/db --config "C:\Program Files\MongoDB\Server\3.6\mongod.cfg"

得到:

2018-07-02T02:49:21.272+0300 I CONTROL [main] 日志文件“c:\data\log\mongod.log”存在;移至“c:\data\log\mongod.log.2018-07-01T23-49-21”。

mongo 开始,然后是show dbs 并查看:

如果我正在写这个 sn-p(没有配置),一切都很好:

mongod --auth --dbpath /data/db --bind_ip 127.0.0.1

mongo 我做错了什么?感谢您的帮助。

【问题讨论】:

  • 为什么您认为在路径周围添加引号后仍然有问题?该消息只是告诉您mongod 旋转了日志文件。而且由于您的配置确实指定了一个日志文件,我希望您在控制台上看到的所有输出都转到该日志。
  • @AnsgarWiechers 因为那时我无法通过mongo 使用mongo --port 27017 -u "myuser" -p "mypassword" --authenticationDatabase "admin" 进程查看我的数据库
  • @AnsgarWiechers show dbs -> 2018-07-02T14:34:47.242+0300 E QUERY [thread1] Error: listDatabases failed:{ "ok" : 0, "errmsg" : "not master and slaveOk=false", "code" : 13435, "codeName" : "NotMasterNoSlaveOk" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 Mongo.prototype.getDBs@src/mongo/shell/mongo.js:65:1 shellHelper.show@src/mongo/shell/utils.js:849:19 shellHelper@src/mongo/shell/utils.js:739:15 @(shellhelp2):1:1show collections同样的错误
  • 你的配置文件指定了replication set,你的守护进程没有从命令行启动。
  • 我认为您需要在启动 Mongo shell 时调用它(请参阅 Ed Harris 提供的答案)。不过,我在 MongoDB 方面没有太多经验。

标签: mongodb powershell


【解决方案1】:

解决方案

感谢Ansgar的推荐,我解决了。

  1. 为避免出现如下错误:not master and slaveOk = false 需要始终使用命令:rs.slaveOk()
  2. 为了避免每次都输入rs.slaveOk()需要在.mongorc.js文件check herehere中添加rs.slaveOk()
  3. 更多详情information.

【讨论】:

    猜你喜欢
    • 2023-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    • 2017-03-24
    • 2011-02-17
    • 1970-01-01
    相关资源
    最近更新 更多