Maybe your replica set configuration is not correct. To check the configuration run the rs.conf() command in your mongo servers. You need to have a mongo host running as primary member.
MongoError: Not master
This error seems like your primary member of replica set is not configured properly.
You can confirm this by entering into mongo shell of the host_one. If mongo shell prompt doesn't show PRIMARY, then it's not configured properly.
Mongo shell prompt of host_two and host_three should show SECONDARY after proper configuration.
Important : Run rs.initiate() on just one and only one mongod instance for the replica set.
You can execute this command on the primary member to make the configuration work properly.
rs.initiate(); cfg = { _id: 'rs0', members: [{ _id: 0, host: 'host_one:27017', priority: 2 }, { _id: 1, host: 'host_two:27017', priority: 1 }, { _id: 2, host: 'host_three:27017', priority: 1 }] }; cfg.protocolVersion = 1; rs.reconfig(cfg, { force: true });
Please note that priority value indicates the relative eligibility of a member to become a primary.
Specify higher values to make a member more eligible to become primary, and lower values to make the member less eligible. A member with a priority of 0 is ineligible to become primary.
You can again check your replica set configuration using this command
rs.conf()
rs.status()is there actually a node which is running as master? Maybe one of the nodes is master or the RS is in a strange state and isn't nothing to do with the client.db.collection.drop()command returning an errornot masterwhen usingsecondaryorsecondaryPreferredread preference will be fixed in the upcoming MongoDB version 3.2.7. Please note that this issue only affects thedropcommand. Other write functions such asinsert,delete, orupdateshould work when usingsecondaryPreferredread preference.