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

preserveNullAndEmptyArrays not working correctly

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Aggregation Framework
    • None
    • ALL

    Description

      Input :

      db.inventory.insert([
      { "_id" : 1, "item" : "ABC", "sizes": [ "S", "M", "L"] },
      { "_id" : 2, "item" : "EFG", "sizes" : [ ] },
      { "_id" : 3, "item" : "IJK", "sizes": "M" },
      { "_id" : 4, "item" : "LMN" },
      { "_id" : 5, "item" : "XYZ", "sizes" : null }
      ]);
      

      Query to execute:

      db.inventory.aggregate( [
         { $unwind: { path: "$sizes", preserveNullAndEmptyArrays: true } }
      ] )
      

      Output :

      { "_id" : 1, "item" : "ABC", "sizes" : "S" }
      { "_id" : 1, "item" : "ABC", "sizes" : "M" }
      { "_id" : 1, "item" : "ABC", "sizes" : "L" }
      { "_id" : 2, "item" : "EFG" }
      { "_id" : 3, "item" : "IJK", "sizes" : "M" }
      { "_id" : 4, "item" : "LMN" }
      { "_id" : 5, "item" : "XYZ", "sizes" : null }
      

      Doubt : Here for the _id : 2 there is an empty array [] for sizez, Now it is eradicated, Actually it should be there like how null values are retained, Then only we will know the value of sizes right, Why it is removing that field

      Attachments

        Activity

          People

            charlie.swanson@mongodb.com Charlie Swanson
            guruskec@gmail.com guru rajan
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: