[SERVER-7768] aggregate command fails with $readPreference Created: 27/Nov/12  Updated: 26/Sep/17  Resolved: 11/Dec/12

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.2.0, 2.2.1
Fix Version/s: 2.3.2

Type: Bug Priority: Critical - P2
Reporter: Bernie Hackett Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Operating System: ALL
Participants:
Case:

 Description   

Note: this seems to only be a problem with the aggregate command. In 2.2.x all other commands seem to ignore $readPreference (support is implemented in 2.3.1 for SERVER-7423)

This effects at least the Java and Python drivers, which always send $readPreference to mongos for certain white listed commands.

aggregate without $readPreference, no issues:

mongos> db.runCommand({'aggregate': 'test', 'pipeline': [{'$project': {'_id': false, 'foo': true}}]})
{ "result" : [ { }, { "foo" : "bar" } ], "ok" : 1 }

aggregate with $readPreference, errors:

mongos> db.runCommand({'aggregate': 'test', 'pipeline': [{'$project': {'_id': false, 'foo': true}}], $readPreference: {'mode': 'primary'}})
{ "ok" : 0, "errmsg" : "unrecognized field \"$readPreference" }

count (as one counter-example) with $readPreference, no issues:

mongos> db.runCommand({'count': 'test', query: {}, $readPreference: {'mode': 'primary'}})
{ "shards" : { "shard0000" : 2 }, "n" : 2, "ok" : 1 }



 Comments   
Comment by zhu daniel [ 29/Nov/12 ]

i got this problem too after i run m/r with 2.10.0 version of java driver. so changed the java driver to 2.9.1. now it works ok.

Comment by auto [ 28/Nov/12 ]

Author:

{u'date': u'2012-11-27T16:51:07Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: SERVER-7768 aggregate command should ignore options that start with $
Branch: master
https://github.com/mongodb/mongo/commit/1aa1cd5d0b6e5d02d6aa0871a3fbc735e9e14ee5

Comment by Bernie Hackett [ 27/Nov/12 ]

This should already be fixed in 2.3.1 (SERVER-7423). We need a fix in 2.2.2. There isn't any good way to work around this in the drivers.

Generated at Thu Feb 08 03:15:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.