So I have this mongo db query which works fine:
db.levels.aggregate([{
$match: {
"_id": {$lt: ObjectId("56410480f91e505237902dae")}
},
},
{ $group:
{
"_id": {"title": "Level 11"},
"totalAmount": { $sum: "$rewardCoins"}
}
}
])
It should get all rows before give id and based on rewardCoins calculate sum.
Now with mgo in golang I'm strugling to get this working... I'm going with pipe but my resultset is empty.
pipe := c.Pipe([]bson.M{{"$match": bson.M{"_id": bson.M{"$lt": level.ID}},
"$group": bson.M{"_id":"$title", "totalReward": bson.M{"$sum": "$rewardCoins"}}}})
res :=[]bson.M{}
pipe.All(&res)
What I'm doing wrong here ? Thanks.
UPDATE
Here is how my simple rows look like in db:
{ "_id" : ObjectId("5613f5ad153678d113d01f4a"), "title" : "Level 1", "rewardCoins" : NumberLong(1000) }
{ "_id" : ObjectId("56159796153678d113d02d60"), "title" : "Level 2", "rewardCoins" : NumberLong(50000) }