$out not working in mongodb Sharding

242 views
Skip to first unread message

yash vora

unread,
Sep 1, 2017, 3:03:11 AM9/1/17
to mongodb-user

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

Rhys Campbell

unread,
Sep 1, 2017, 4:40:38 AM9/1/17
to mongodb-user
When running on a secondary you need to execute..

rs.slaveOk();

Before you can use it.



Although the manual doesn't explicitly state it I think you need to run this on a PRIMARY server



yash vora

unread,
Sep 4, 2017, 1:51:38 AM9/4/17
to mongodb-user
Thanks Rhys,

I executed as per instructed by you and from windows cmd prompt i can query out my results to another collection.

Below are the steps which are performed

If anybody is using $out parameter in there mongodb query to query out sharded collection result to another collection , please follow below steps : 

1) run rs.slaveOk(); by logging in each and every primary shards 
2) Connect to mongos service. 
3) Execute your query containing $out parameter. 
4) Your result will be there.

Again Rhys Thanks for the solution.
Cheers !!!

Kevin Adistambha

unread,
Sep 4, 2017, 11:45:23 PM9/4/17
to mongodb-user

Hi

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

Could you elaborate on the steps you performed to arrive at this error message? If you’re connecting through mongos, you shouldn’t see this message, even with an aggregation query with a $out stage. This may be the result if you’re inadvertently connected to one of the secondaries in a shard instead of mongos, since the error not master and slaveOk=false is a general error if you’re trying to read from a secondary and has nothing to do with $out.

The slaveOk() setting on a secondary only allows the current connection to read from the connected secondary (see rs.slaveOk()). That is, this is not a global flag allowing any other connection to read from this secondary.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages