[SERVER-71045] Use of $$ROOT in $expr in $match fails on servers prior to 6.0 Created: 02/Nov/22  Updated: 05/Dec/22  Resolved: 10/Nov/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Robert Stam Assignee: Backlog - Query Optimization
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-64764 $expr rewrite is not prepared to hand... Closed
Related
related to CSHARP-4244 Support object comparison at root lev... Closed
Assigned Teams:
Query Optimization
Operating System: ALL
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

Participants:

 Description   

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' }] } } }])



 Comments   
Comment by Charlie Swanson [ 10/Nov/22 ]

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

Generated at Thu Feb 08 06:17:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.