Details
-
Bug
-
Resolution: Done
-
Minor - P4
-
None
-
3.0.3
-
None
-
Fully Compatible
-
ALL
Description
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