Mongodb – $out not working in mongodb Sharding

mongodbmongodb-3.4sharding

I am bit stuck in MongoDB while exporting my output to some other collection.

Scenario :

Actually, i want to query out my result to another collection which is successful in normal mongoDB( without Sharding).
But, when i Shard that same DB , Mongo DB is giving me error code 13435 which is cannot read from replica set and gives me below error set :

Error: command failed: {
    "ok" : 0,
    "errmsg" : "listIndexes failed: { ok: 0.0, errmsg: \"not master and slaveOk=false\", code: 13435, codeName: \"NotMasterNoSlaveOk\" }",
    "code" : 18631,
    "codeName" : "Location18631"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
@(shell):1:1

Currently working on below versions of mongoDB :
Version : 3.4.6
OS : Windows Server 2012

Best Answer

The error message indicates that, in your cluster, there was shard what didn't have primary available and query went to secondary and with the current configuration, a query to secondary was not allowed.

So, what was a reason that there was no primary? An answer to that is the key to solve the problem.

Can you check (by login to every RS) that every sharded replica set have primary available? Second possibility is that config servers don't have up-to-date information of your shards configuration... But that should not be possible if your cluster works other ways fine.