Relatively Simple Scenario:
I have this Voucher
object which has a user
property (of type ObjectId
). I want to get the sum of all voucher values for a single user. Here is my current strategy, which returns an empty array:
Voucher.aggregate [
{ $match : { user : new ObjectId(user_id), expires : { $gt : new Date() } } }
{ $group : { _id : null, sum : { $sum : '$value' } } }
], (err, result)->
console.log err
console.log result
Removing the match for the user
id, and leaving the expires
field will return results. So the question becomes what is wrong with the match on user
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…