-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
ALL
-
Query 2020-01-27, Query 2020-02-10, Query 2020-03-09
-
None
-
0
-
None
-
None
-
None
-
None
-
None
-
None
- MongoDB 4.0.7 add mergeByPBRT option between mongos and mongod
- if mongos has upgraded to a new version,the normal aggregation command to mongod below 4.0.7 will cause access error.
mongos> db.test.aggregate([{"$match":{"c32":17}}, {"$group":{"_id":null, "total":{"$sum":"$float"}}}]) 2019-12-30T19:59:16.398+0800 E QUERY [js] Error: command failed: { "ok" : 0, "errmsg" : "unrecognized field 'mergeByPBRT'", "code" : 9, "codeName" : "FailedToParse", "operationTime" : Timestamp(1577707153, 1), "$clusterTime" : { "clusterTime" : Timestamp(1577707155, 3), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
Workaround,only add mergeByPBRT option in change stream aggregation command.
diff --git a/src/mongo/s/commands/cluster_aggregate.cpp b/src/mongo/s/commands/cluster_aggregate.cpp index d58ce76220..a2c308a353 100644 --- a/src/mongo/s/commands/cluster_aggregate.cpp +++ b/src/mongo/s/commands/cluster_aggregate.cpp @@ -215,7 +215,9 @@ BSONObj createCommandForTargetedShards( targetedCmd[AggregationRequest::kNeedsMergeName] = Value(true); // If this is a change stream, set the 'mergeByPBRT' flag on the command. This notifies // the shards that the mongoS is capable of merging streams based on resume token. - targetedCmd[AggregationRequest::kMergeByPBRTName] = Value(litePipe.hasChangeStream()); + if (litePipe.hasChangeStream()) { + targetedCmd[AggregationRequest::kMergeByPBRTName] = Value(litePipe.hasChangeStream()); + } targetedCmd[AggregationRequest::kCursorName] = Value(DOC(AggregationRequest::kBatchSizeName << 0)); }