MongoDB aggregation framework $subtract
问题 I'm want use mongodb to achieve simple query like mysql "select a-b from table", but aggregation framework query result is not right. data: { "_id" : ObjectId("511223348a88785127a0d13f"), "a" : 1, "b" : 1, "name" : "xxxxx0" } { "_id" : ObjectId("511223348a88785127a0d13f"), "a" : 2, "b" : 2, "name" : "xxxxx1" } mongodb cmd: db.site.aggregate([ { $match: { "a" : {$exists:true}, "b" : {$exists:true}, } }, { $project: { _id : 0,name : 1, r1: {$subtract:["$a", "$b"]} } }, { $limit: 100 }, ]);