1
votes

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?

2
Are you certain about your connection? Can you demonstrate how you are connecting and the available nodes? Because the error does indeed suggest that you are in fact connected to a secondary node, and it is of course only possible to use $out when connected to a primary.Neil Lunn
Appears to only be occurring when executed through Robo 3T. Executing through a raw shell works fine.Ellis

2 Answers

1
votes

Appears to only be occurring when executed through Robo 3T. Executing through a raw shell works fine.

0
votes

I had the same problem today and solved it by removing the "getCollection".

Can you try running:

   db.restaurants.aggregate([
   {$match : {$text : {$search : "steak"}}},
   {$out : "steak_restaurants"}
   ])