匹配不与Mongoose中的聚合

没有匹配,我得到我需要的输出,当我提供$匹配值,我得到一个空的答复。 什么可能是空回应的原因? 有没有什么不同的方式来调用$匹配参数?

var query = {"section":"324444"}; // 324444 is section schema _id value Transaction.aggregate({ "$match": query },{ "$group": { "_id": "$user", "section": { "$first": "$section"}, "amount": { "$sum": { "$cond": ["$credit", "$amount", { "$subtract": [ 0, "$amount" ] }] }} }}) .exec(function(err, transactions) { // Transactions List Grouped User wise }); // Transaction schema var transSchema = new Schema({ user: {type: mongoose.Schema.Types.ObjectId, ref: 'User',required: true}, section: {type: mongoose.Schema.Types.ObjectId, ref: 'Section',required: true}, amount: { type: Number, required: true}, credit: { type: Boolean, default: true } created_at: Date }); // Section schema var sectionSchema = new Schema({ name: { type: String, required: true}, created_at: Date }); 

更新:尝试与下面的代码,但我得到空的答复。 另外我怎么处理,当我必须匹配从2个或更多的集合(例如说我有另一个名为SubSection集合类似于在交易架构部分)

码:

  Transaction.aggregate({ "$lookup": { "from": Section.collection.name, "localField": "section", "foreignField": "_id", "as": "section" }}, { "$match": {"section._id":"324444"} }, { "$group": { "_id": "$user", "section": { "$first": "$section"}, "amount": { "$sum": { "$cond": ["$credit", "$amount", { "$subtract": [ 0, "$amount" ] }] }} }}) .exec(function(err, transactions) { // Results });