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

Question about aggregation behavior

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.0.5
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      The following behavior seems like a bug to me:

      > db.test.insert({ "_id" : ObjectId("55d386eeb4a9494cd24e94fc"), "name" : "test", "myarray" : [ ] });
      WriteResult({ "nInserted" : 1 })
      > db.test.aggregate([{'$group' : {'_id' : '$name', 'thing' : {'$first' : '$myarray.made_up_field'}}}]);
      { "_id" : "test", "thing" : [ ] }
      

      Why does "thing" get set to an empty array? It should be null?

      I ran into this problem while doing a $push like the following during a $group phase

      'inventory' => ['$push' => [
        warehouse' => '$sku.inventory.warehouse',
        at_once' => '$sku.inventory.at_once'
      ]]
      

      and getting an empty array for warehouse often times instead of a string when sku.inventory was an empty array.

            Assignee:
            asya.kamsky@mongodb.com Asya Kamsky
            Reporter:
            nefiga Ben Rotz
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: