I have a mongodb cluster containing two shards, each a replication set of 3 nodes, and a config server cluster again with three nodes.
All seems to be in order apart from when I attempt to write a collection at the end of an aggregation pipeline using the $out operator:
db.getCollection('restaurants').aggregate([
{$match : {$text : {$search : "steak"}}},
{$out : "steak_restaurants"}
])
This is return the following error:
ailed to execute script.
Error: Assert: 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
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
The mongo shell is connected to a mongos router. If I execute the same against mongod, this works fine.
The error suggests that somehow reading is taking place from a secondary, however, I have not set any read preference and I would have thought that mongos would resolve the primary correctly by itself. Any ideas or insight please?
$out
when connected to a primary. – Neil Lunn