【发布时间】:2013-03-19 08:39:04
【问题描述】:
我想在 mapReduce 之后填充字段。
mongoose.connection.db.collection('createdCollectionNameForResults', function(err, collection) {
collection.find({}).populate('ref_field').toArray(function(err, items) {
res.send(200, items)
});
});
但在这里,它给出了错误:
TypeError: Object # has no method 'populate'
因为 collection.find({}) 返回 mongodb 游标。如何填充 ref_field?
【问题讨论】:
-
您在本机驱动程序集合上调用
find。您需要在 Mongoose 模型上调用find,populate才能工作。 -
是的,但是我应该怎么做呢?
-
为您的
mapReduce创建的集合创建架构和模型,然后像任何其他猫鼬模型一样查询它。见docs。
标签: mongodb mapreduce mongoose