Details
-
Improvement
-
Resolution: Done
-
Minor - P4
-
None
-
Fully Compatible
-
Query 2020-11-30, Query 2020-12-14
Description
This could be described as $ifNull expression that accepts multiple arguments (rather than current two only). First non-null expression would be used.
Original description:
It would be great if instead of making a long list of conditionals you could use any $any operator to get the first of the fields that exists.
Ex:
var docs = [ |
{ 'a': true }, |
{ 'b': true }, |
{ 'a': true} |
...
|
]
|
{ '$project': |
{ 'wow': |
{ '$any': [ '$a', '$b', '$b.nested', ... ] } |
}
|
}
|
This would make it easy to project an _id for use by a $group stage in situations where you have varied document schema.
For example, the next stage of the pipeline could be:
{ $group:
|
{
|
_id: { wow: '$wow' }, |
count: { '$sum': 1 } |
}
|
}
|
Attachments
Issue Links
- is depended on by
-
CSHARP-3282 Extend $ifNull to accept more than two arguments
-
- Closed
-
-
JAVA-3900 Extend $ifNull to accept more than two arguments
-
- Closed
-
- is documented by
-
DOCS-14034 Investigate changes in SERVER-12573: Extend $ifNull to accept more than two arguments was Add $any/$first/$oneOf operator to projection
-
- Closed
-