I am trying to start mongod with a config file on MongoDB 3.2 on Ubuntu 14.04. I can launch mongod by issuing the command myself, but I can't get it to work with the config file.

Here's the command I'm issuing:

sudo mongod --replSet rs0 --logpath /var/log/mongodb/mongod.log --dbpath /data/db --storageEngine wiredTiger --fork

When I run this command, I can then run mongo to enter the mongo shell and successfully use the database.

I don't see a difference between the command I'm issuing and the config file, which I call with sudo mongod --config /etc/mongod.conf. When I run this, and try a command in the same mongo shell I had successfully used for the prior query, I get

2017-01-31T10:55:44.899-0800 E QUERY    [thread1] Error: error: { "ok" : 0, "errmsg" : "not master and slaveOk=false", "code" : 13435 } :

and here is my /etc/mongod.conf. How are these different?:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
  dbPath: "/data/db"
    enabled: true
  engine: "wiredTiger"
#  mmapv1:
#  wiredTiger:

# where to write logging data.
  destination: file
  logAppend: true
  path: "/var/log/mongodb/mongod.log"

# network interfaces
  port: 27017

  fork: true



  replSetName: rs0
#  oplogSizeMB: 1024


## Enterprise-Only Options:



1 Answer 1


That error message "not master and slaveOk=false" is what you get when you try to query on a secondary server. If you're getting that message, that implies that:

  1. The server has successfully started
  2. The server has successfully joined the replica set
  3. A different server is currently Primary

You should be able to check that by running rs.status() in the shell (assuming your user account has replicaset administration privileges).

If you want to run a query on this server to confirm that it is working (even though it is currently a secondary), you can use the rs.slaveOk call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.