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

$ifNull behaves differently in latest

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.1.0-rc0
    • Component/s: None
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Behavior in 5.0.0 and earlier:

      MongoDB Enterprise > db.version()
      5.0.0
      MongoDB Enterprise > db.test.find()
      { "_id" : 1 }
      { "_id" : 2, "X" : null }
      { "_id" : 3, "X" : 3 }
      MongoDB Enterprise > db.test.aggregate([{ $project : { Z : { $ifNull : ["$X", null] } } }])
      { "_id" : 1, "Z" : null }
      { "_id" : 2, "Z" : null }
      { "_id" : 3, "Z" : 3 }
      MongoDB Enterprise >
      

      Unexpected behavior in latest:

      MongoDB Enterprise > db.version()
      5.0.0-alpha0-1698-gf4169a7
      MongoDB Enterprise > db.test.find()
      { "_id" : 1 }
      { "_id" : 2, "X" : null }
      { "_id" : 3, "X" : 3 }
      MongoDB Enterprise > db.test.aggregate([{ $project : { Z : { $ifNull : ["$X", null] } } }])
      { "_id" : 1 } // NOTE: the Z field is missing
      { "_id" : 2, "Z" : null }
      { "_id" : 3, "Z" : 3 }
      MongoDB Enterprise >
      

       

      Show
      Behavior in 5.0.0 and earlier: MongoDB Enterprise > db.version() 5.0 . 0 MongoDB Enterprise > db.test.find() { "_id" : 1 } { "_id" : 2 , "X" : null } { "_id" : 3 , "X" : 3 } MongoDB Enterprise > db.test.aggregate([{ $project : { Z : { $ifNull : [ "$X" , null ] } } }]) { "_id" : 1 , "Z" : null } { "_id" : 2 , "Z" : null } { "_id" : 3 , "Z" : 3 } MongoDB Enterprise > Unexpected behavior in latest: MongoDB Enterprise > db.version() 5.0 . 0 -alpha0- 1698 -gf4169a7 MongoDB Enterprise > db.test.find() { "_id" : 1 } { "_id" : 2 , "X" : null } { "_id" : 3 , "X" : 3 } MongoDB Enterprise > db.test.aggregate([{ $project : { Z : { $ifNull : [ "$X" , null ] } } }]) { "_id" : 1 } // NOTE: the Z field is missing { "_id" : 2 , "Z" : null } { "_id" : 3 , "Z" : 3 } MongoDB Enterprise >  
    • Sprint:
      QE 2021-08-23, QE 2021-09-06, QE 2021-09-20, QE 2021-10-04
    • Linked BF Score:
      153

      Description

      $ifNull behaves differently in latest when the replacement value is null. In earlier versions it returned null. In latest it omits the field entirely.

      While it may sound silly to use a replacement value of null, the LINQ provider in the C# driver uses this construct to replace a missing field with an explicit null-valued field.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ethan.zhang Ethan Zhang
              Reporter:
              rstam Robert Stam
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: