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

add expression to get value by keyname from object

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Query 2020-08-10, Query 2020-08-24, Query Optimization 2021-04-05, Query Optimization 2021-04-19, Query Optimization 2021-05-03

      Description

      While it's possible via combined use of $objectToArray and $filter with $map, it would be nice to have a simple expression to get value of particular field of an object:

      db.foo.find()
      { _id: 1, a: 5, foo: { b: "a", c: 99.9 } }
      db.foo.aggregate({$project:{ foo_c_is: {$getField:[ "c", "$foo" ] } } })
      { _id: 1, foo_c_is: 99.9 }
      

      This will allow easily plucking out a value when the field name is stored in another part of the same document, or when it has some funny character that precludes it being used as subfield name (like leading "$") as in SERVER-30365 and SERVER-14466 or embedded '.' when querying oplog or system.profile collections.

      Second argument could be optional and default to "$$ROOT".

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alya.berciu Alya Berciu
              Reporter:
              asya Asya Kamsky
              Participants:
              Votes:
              14 Vote for this issue
              Watchers:
              22 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: