preserveNullAndEmptyArrays not working correctly

XMLWordPrintableJSON

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

      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
            Reporter:
            guru rajan
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: