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

preserveNullAndEmptyArrays not working correctly

    • Type: Icon: Bug Bug
    • Resolution: Incomplete
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      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

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

              Created:
              Updated:
              Resolved: