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

$ifNull behaves differently in latest

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 5.1.0-rc0
    • None
    • None
    • Fully Compatible
    • ALL
    • 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 >  
    • QE 2021-08-23, QE 2021-09-06, QE 2021-09-20, QE 2021-10-04
    • 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

              ethan.zhang@mongodb.com Ethan Zhang (Inactive)
              robert@mongodb.com Robert Stam
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: