1

Upon trying to connect mongodb secondary node from application :

08:11:2018 16:01:00.552 - error: A hook (orm) failed to load! 08:11:2018 16:01:00.558 - error: Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running? Error details: MongoError: no valid seed servers in list

I can access the secondary DB by manually entering the command rs.slaveOk(); , but the same wont suffice as I need the application to have dynamic read access everytime the DB is bieng queried

1

1 Answer 1

2

08:11:2018 16:01:00.552 - error: A hook (orm) failed to load! 08:11:2018 16:01:00.558 - error: Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running? Error details: MongoError: no valid seed servers in list

As per your it seems like that your mongod server has not started.

As per MongoDB documentation here All read preference modes except primary may return stale data because secondaries replicate operations from the primary with some delay. [1] Ensure that your application can tolerate stale data if you choose to use a non-primary mode.

MongoDB drivers support five read preference modes.

Read Preference Mode    Description

primary                 Default mode. All operations read from the current replica set primary.                                                       
                        Multi-document transactions that contain read operations must use read preference primary.

                        All operations in a given transaction must route to the same member.

primaryPreferred        In most situations, operations read from the primary but if it is unavailable, operations read from secondary members.

secondary               All operations read from the secondary members of the replica set.

secondaryPreferred      In most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.

nearest                Operations read from member of the replica set with the least network latency, irrespective of the member’s type.

As MongoDB documented setSlaveOk() This allows the current connection to allow read operations to run on secondary members. See the readPref() method for more fine-grained control over read preference in the mongo shell.

db.getMongo().setSlaveOk()

For further your ref here, here and here

1
  • I added the following in the DB accessing user home directory and seems to be working fine . echo "rs.slaveOk()" >> ~/.mongorc.js . My query is that if we add the same command to a node which is primary , whether it will cause any impact on the default primary DB operation ?
    – John
    Commented Dec 11, 2018 at 12:36

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.