// This is a command with secondary-possible read pref
|
// Only certain commands are supported for secondary operation.
|
BSONObj actualQueryObj;
|
if (strcmp(queryObj.firstElement().fieldName(), "query") == 0) {
|
actualQueryObj = queryObj["query"].embeddedObject();
|
}
|
else {
|
actualQueryObj = queryObj;
|
}
|
In practice, the embedded "wrapped" command can have a fieldname of either 'query' or '$query' and we only check for 'query'. The Server Selection spec actually mandates that drivers use '$query': see ( https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#id17).
The effect is that for commands that can run on a secondary, such as inline mapreduce, mongos will incorrectly run the commands on a primary of the shard, even with readPreference mode secondary. Note that this affects drivers OTHER than the shell, which wraps commands with 'query'.
EDIT: in practice this is not an issue as mongos already unwraps the queries (correctly) by the time they reach this point of the codebase.
|