Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

Issue for connecting to Replica set's secondaries in MongoDB

$
0
0

I'm developing a restful server with MongoDB and an official driver for node.js.

I found that Read Preference "nearest" mode calculates the nearest node every operation and it's slower than a direct read from a node.

Thus, I thought if I connect to the secondaries, I can get the best read speed.

When I try to connect to a secondary node in a Replica Set with a node.js driver I got an error message saying:

{ MongoError: not master and slaveOk=false
    at Function.MongoError.create (/home/jonah/NetBeansProjects/mongoDBTester/node_modules/mongodb-core/lib/error.js:32:15)
    at /home/jonah/NetBeansProjects/mongoDBTester/node_modules/mongodb-core/lib/connection/pool.js:462:72
    at authenticateStragglers (/home/jonah/NetBeansProjects/mongoDBTester/node_modules/mongodb-core/lib/connection/pool.js:410:16)
    at .messageHandler (/home/jonah/NetBeansProjects/mongoDBTester/node_modules/mongodb-core/lib/connection/pool.js:444:5)
    at Socket.<anonymous> (/home/jonah/NetBeansProjects/mongoDBTester/node_modules/mongodb-core/lib/connection/connection.js:306:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:177:18)
    at Socket.Readable.push (_stream_readable.js:135:10)
    at TCP.onread (net.js:542:20)
  name: 'MongoError',
  message: 'not master and slaveOk=false',
  ok: 0,
  errmsg: 'not master and slaveOk=false',
  code: 13435 }

But I found MongoChef which is a GUI administration app that can connect to the secondary and read all data, no writing of course.

Can anyone tell me how to connect to the secondary with a node.js official driver?


Viewing all articles
Browse latest Browse all 17268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>