0
我已经测试了以下聚集在mongodb外壳上,它工作正常,但是它似乎并没有与猫鼬一起工作。我已经搜索了类似的主题和问题,但他们的解决方案并不能解决我的问题Mongodb聚合不与猫鼬
文档结构是这样的
{
name,
id,
contacts:[{
contactId, //I need an array of this field
dateAdded
}, {
contactId,
dateAdded
},
{}..]
}
的mongooose模式是:
var AccountSchema = new mongoose.Schema({
email: { type: String, unique: true },
password: { type: String },
name: {
first: { type: String },
last: { type: String },
full: { type: String }
},
contacts: [Contact]
});
,这里是聚集:
Account.aggregate({
$match: { _id: accountId }
}, {
$unwind:"$contacts"
},
{
$group: {
_id: '$_id',
list: { $push:'$contacts.accountId' }
}
}, {
$project: {
_id: 0,
contacts: 1
}
}, function(err, doc) {
// var l=doc.result[0].list;
callback(doc);
});
在MongoDB的外壳,汇聚返回contactID的数组,如下所示,但它返回一个Mongoose上的空数组
{
"result" : [
{
"_id" : null,
"list" : [
ObjectId("xxxbnbnb2013-06-23T16:24:03.785Z"),
ObjectId("mnmnmnmui2013-06-23T16:24:04.688Z")
]
}
],
"ok" : 1
}