[DOCS-14034] Investigate changes in SERVER-12573: Extend $ifNull to accept more than two arguments was Add $any/$first/$oneOf operator to projection Created: 04/Dec/20  Updated: 13/Nov/23  Resolved: 10/Mar/21

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: 4.9.0, Server_Docs_20231030, Server_Docs_20231106, Server_Docs_20231105, Server_Docs_20231113

Type: Task Priority: Major - P3
Reporter: Backlog - Core Eng Program Management Team Assignee: Jason Price
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-12573 Extend $ifNull to accept more than tw... Closed
Participants:
Days since reply: 2 years, 48 weeks, 1 day ago
Epic Link: DOCSP-9747
Story Points: 3

 Description   

Description

Downstream Change Summary

Previously, $ifNull only supported 2 arguments. Now, $ifNull accepts 2+ arguments and returns the first that is not null (and not undefined or missing). If all arguments are null/undefined/missing, the last argument is returned.

Description of Linked Ticket

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 }
  }
}

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Githook User [ 09/Mar/21 ]

Author:

{'name': 'Jason Price', 'email': 'jason.price@mongodb.com', 'username': 'jason-price-mongodb'}

Message: DOCS-14034-Extend-ifNull-to-accept-more-than-two-arguments
Branch: v5.0
https://github.com/mongodb/docs/commit/25b4e8eaf187a344e3485415a38879c86c42222f

Generated at Thu Feb 08 08:09:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.