0

In config file I have:

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

enter image description here

I'm trying to connect using mongod process like in documentation:

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

And getting:

Error reading config file: No such file or directory
try 'C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe --help' for more information

enter image description here

Then trying with quotes

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

and getting:

2018-07-02T02:49:21.272+0300 I CONTROL [main] log file "c:\data\log\mongod.log" exists; moved to "c:\data\log\mongod.log.2018-07-01T23-49-21".

enter image description here Starting mongo, then show dbs and see: enter image description here

If I'm writting this snippet (without config), everything is fine:

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

enter image description here With mongo: enter image description here What I'm doing wrong? I appreciate any help.

invzbl3
  • 5,872
  • 9
  • 36
  • 76
  • Why do you think something is still wrong after you added quotes around the path? The message is just telling you that `mongod` rotated the log file. And since your config does specify a log file I'd expect all the output you'd otherwise see on the console to go to that log. – Ansgar Wiechers Jul 02 '18 at 07:59
  • @AnsgarWiechers because then I can't see my databases via `mongo` process using `mongo --port 27017 -u "myuser" -p "mypassword" --authenticationDatabase "admin"` – invzbl3 Jul 02 '18 at 11:47
  • @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:1`. `show collections` same error – invzbl3 Jul 02 '18 at 11:47
  • 1
    Your config file specifies a [replication set](https://stackoverflow.com/q/8990158/1630171), your daemon start from the commandline does not. – Ansgar Wiechers Jul 02 '18 at 12:03
  • @AnsgarWiechers thank you a lot, solve it by using `rs.slaveOk()`, but can I add `rs.slaveOk()` directly to my config file instead of permanently writing this before `show dbs` and `show collections`? – invzbl3 Jul 02 '18 at 12:14
  • 1
    I think you need to invoke it when starting the Mongo shell (see the answer provided by Ed Harris). I don't have that much experience with MongoDB, though. – Ansgar Wiechers Jul 02 '18 at 12:54

1 Answers1

0

Solution

Thanks to recomendation by Ansgar, I solved it.

  1. To avoid the error like: not master and slaveOk = false need always using the command: rs.slaveOk().
  2. To avoid typing rs.slaveOk() every time need to add rs.slaveOk() in .mongorc.js file check here and here
  3. More detail information.
invzbl3
  • 5,872
  • 9
  • 36
  • 76