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

`$getField` doesn't work with a dynamic `field`

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 5.0.9
    • None
    • None
    • None
    • ALL

    Description

       

      db.test.insert({ a: 'a' });
      db.test.aggregate([{ $addFields: { result: { $getField: { field: { $concat: ['$a', 'a'] }, input: { aa: 1 } } } } }]);
      

      This leads to:

       

      MongoServerError: Invalid $addFields :: caused by :: $getField requires 'field' to evaluate to a constant, but got a non-constant argument

      I don't understand why that happens (and believe it's a bug). According to getField's documentation `field` can be any expression that resolves to a string. In my example it is such but it doesn't work.

       

       

      Attachments

        Issue Links

          Activity

            People

              anton.korshunov@mongodb.com Anton Korshunov
              alien Boris Petrov
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: