Info
The following aggregate command works on 6.0 but not on earlier versions:
db.C.aggregate([{ $match : { $expr : { $eq : ['$$ROOT', { _id : 2, Name : 'Jane Doe' }] } } }])
Top User Comments
charlie.swanson commented on Thu, 10 Nov 2022 19:51:43 +0000:
Thanks for reporting robert@mongodb.com. We noticed this and fixed it, but didn't consider backporting. I checked the backport requested box and we'll triage that over in SERVER-64764
Steps to Reproduce
Create test data:
db.C.insertMany([{ _id : 1, Name : "John Doe" }, { _id : 2, Name : "Jane Doe" }])
Execute command:
db.C.aggregate([{ $match : { $expr : { $eq : ['$$ROOT', { _id : 2, Name : 'Jane Doe' }] } } }])
Expected result:
> db.C.aggregate([{ $match : { $expr : { $eq : ['$$ROOT', { _id : 2, Name : 'Jane Doe' }] } } }])
[ { _id: 2, Name: 'Jane Doe' } ]
Result in 5.0:
> db.C.aggregate([{ $match : { $expr : { $eq : ['$$ROOT', { _id : 2, Name : 'Jane Doe' }] } } }])
MongoServerError: Failed to optimize pipeline :: caused by :: Failed to optimize expression :: caused by :: FieldPath::tail() called on single element path