-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Fully Compatible
-
Query 2020-08-10, Query 2020-08-24, Query Optimization 2021-04-05, Query Optimization 2021-04-19, Query Optimization 2021-05-03
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".
- causes
-
COMPASS-5173 Add expression to get value by keyname from object
- Closed
-
MONGOSH-1003 Add expression to get value by keyname from object
- Closed
-
VSCODE-299 Add expression to get value by keyname from object
- Closed
- is depended on by
-
SERVER-21889 Oplog format for $set operations on subdocuments creates format that is not queryable
- Backlog
-
COMPASS-5126 Add expression to set value in object given field name expression
- Closed
-
MONGOSH-1010 Add expression to set value in object given field name expression
- Closed
-
VSCODE-300 Add expression to set value in object given field name expression
- Closed
- is duplicated by
-
SERVER-38124 executing the expression in a field
- Closed
-
SERVER-38463 Add $objectValueAt Expression
- Closed
-
SERVER-37341 get value from document using expression
- Closed
- is related to
-
SERVER-56546 Update $getField expression syntax
- Closed
-
SERVER-56224 Support $getField in SBE
- Backlog
-
SERVER-30575 Please add escaping convention for dot and dollar signs!
- Backlog
- related to
-
SERVER-14466 Support projecting the $id or $ref for a DBRef() field
- Closed
-
PHPLIB-24 Implement DBRef model class
- Closed
-
SERVER-30365 How to exclude (sub)fields starting with $ in a query projection
- Backlog
-
SERVER-41611 add expression to set value in object given field name expression
- Closed
-
SERVER-57914 Make $getField return missing if "input" is missing or not an object
- Closed