Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3282

Extend $ifNull to accept more than two arguments

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

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

            Assignee:
            Unassigned Unassigned
            Reporter:
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: