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

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

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.9
    • Component/s: None
    • None
    • ALL

       

      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.

       

       

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

              Created:
              Updated:
              Resolved: