$ifNull doesn't work as expected

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: 3.0.3
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I've been using MongoDB v3.0.3 and I tried the below codes. However $ifNull didn't fill the array. So I can't handle null Array issues;

      Aggregation codes;

      db.users.aggregate([{ $match: { "_id" : ObjectId("55d31f922d934c7007f048cf") } }, { $project: { 'solv': { $ifNull: [ '$solved', [{ point: 5 }] ] }, code:1 } }, {$group:{ _id:"$_id", score: { $sum: "$solv.point" } }}])
      

      Console output;

      { "_id" : ObjectId("55d31f922d934c7007f048cf"), "score" : 0 }
      

      Another aggregation without $group;

      db.users.aggregate([{ $match: { "_id" : ObjectId("55d31f922d934c7007f048cf") } }, { $project: { 'solv': { $ifNull: [ '$solved', [{ point: "0" }] ] } } }])
      

      Console output;

      { "_id" : ObjectId("55d31f922d934c7007f048cf"), "solv" : [ ] }
      

      Not: I've tried by using MongoDB native driver and also Mongo console directly.

      An example of Asya Kamsky:
      http://stackoverflow.com/a/13898556/3765109

            Assignee:
            Unassigned
            Reporter:
            efkan turen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: