Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "_id" : ObjectId("5a377b895a2840568b1034d5"),
- "reportId" : 1234,
- "quantity" : 346
- },
- {
- "_id" : ObjectId("5a377b935a2840568b1034d6"),
- "reportId" : 1234,
- "users" : 96
- },
- {
- "_id" : ObjectId("5a377ba35a2840568b1034d7"),
- "reportId" : 2345,
- "quantity" : 566
- },
- {
- "_id" : ObjectId("5a377bac5a2840568b1034d8"),
- "reportId" : 2345,
- "users" : 66
- }
- {'reportId': 1234, 'total':quantity * users}
- and so on
- where total in the multiplication of users and quantity
- db.test1.aggregate([
- {'$group':
- { '_id':'$reportId',
- 'total':{'$multiply':['$users','$quantity']}
- }
- }])
- assert: command failed: {
- "ok" : 0,
- "errmsg" : "The $multiply accumulator is a unary operator",
- "code" : 40237,
- "codeName" : "Location40237"
- } : aggregate failed
- db.test1.aggregate([ {
- '$group':
- { '_id':'$reportId',
- 'document':{'$push':{'reportId':'$reportId',
- 'quantity':'$quantity','users':'$users'}}}},
- {'$unwind':'$document'}])
- { "_id" : 2345, "document" : { "reportId" : 2345, "quantity" : 566 } }
- { "_id" : 2345, "document" : { "reportId" : 2345, "users" : 66 } }
- { "_id" : 1234, "document" : { "reportId" : 1234, "quantity" : 346 } }
- { "_id" : 1234, "document" : { "reportId" : 1234, "users" : 96 } }
Add Comment
Please, Sign In to add comment