-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: 5.3.1
-
Component/s: Aggregation
-
None
-
(copied to CRM)
-
None
-
Java Drivers
-
None
-
None
-
None
-
None
-
None
-
None
consider two collections collectionA and collectionB. When we do this aggregation
// code placeholder
collectionA.aggregate(…)
with a pipeline like
[ { $match: {foo: "bar"} }, { $merge: { "into": "collectionB", "on": "_id", "whenMatched": "merge", "whenNotMatched" : "fail" } ]
Then the business code is returned a cursor that iterates over the whole collectionB.
From my experiments, it looks as if the command executed by the java driver is equivalent to:
db.collectionA.aggregate(…) // wait until the command is over db.collectionB.find({}) // return this cursor to the caller.
The cursor returned by the aggregation is supposed to yield no document, by design of the $merge stage. Somehow, the cursor returned yield the content of the whole collection that is the target of the $merge.
- It does not matter if the $match matches something or not.
- In the case there is a match, then the merge is observed in collectionB : the write does occur.
- this is not reproducible in the mongo shell or with the golang driver
- this is reproducible with a bunch of mongodb server including
- mongodb-community/6.0.4
- atlas cluster 8.0.4
- docker image mongodb/mongodb-atlas-local:8.0.4
- links to