Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-71045

Use of $$ROOT in $expr in $match fails on servers prior to 6.0

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • None
    • None
    • Query Optimization
    • ALL
    • Hide

      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
      

      Show
      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

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

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              robert@mongodb.com Robert Stam
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: