I saw a lot of questions in the same way, but somehow I still cannot successfully connect to the slave MongoDB.
I start my cluster on Kubernetes using mongo-k8s-sidecar , connecting my application directly to the wizard works fine, however whenever I try to connect to a slave, I cannot read, here is the error code:
MongoError: not master and slaveOk=false
I use Node.js for my application, and this is how I connect:
var mongodb = require('mongodb').Db;
var Server = require('mongodb').Server
var db = new mongodb('dbname', new Server("localhost",27017,{slaveOk: true}));
db.open(function(err, conn){
if (err){
callback(err);
}else {
client=conn;
client.createIndex("tablename", {field:1}
, {background:true}, function(err, i) {
logger.info(err);
});
What am I missing here?
source
share