How to specify the path to config file in mongodb


How to specify the path to config file in mongodb



In config file I have:


systemLog:
destination: file
logAppend: true
path: c:datalogmongod.log
storage:
dbPath: c:datadb
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:


mongod


C:Program FilesMongoDBServer3.6bin> mongod --auth --dbpath /data/db --config C:Program FilesMongoDBServer3.6mongod.cfg



And getting:



Error reading config file: No such file or directory
try 'C:Program FilesMongoDBServer3.6binmongod.exe --help' for more information



enter image description here



Then trying with quotes


C:Program FilesMongoDBServer3.6bin> mongod --auth --dbpath /data/db --config "C:Program FilesMongoDBServer3.6mongod.cfg"



and getting:



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



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


mongo


show dbs



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.


mongo





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 2 at 7:59



mongod





@AnsgarWiechers because then I can't see my databases via mongo process using mongo --port 27017 -u "myuser" -p "mypassword" --authenticationDatabase "admin"
– invzbl3
Jul 2 at 11:47



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:1. show collections same error
– invzbl3
Jul 2 at 11:47



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





Your config file specifies a replication set, your daemon start from the commandline does not.
– Ansgar Wiechers
Jul 2 at 12:03





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 2 at 12:54





1 Answer
1



Solution



Thanks to recomendation by Ansgar, I solved it.


not master and slaveOk = false


rs.slaveOk()


rs.slaveOk()


rs.slaveOk()


.mongorc.js






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages