2013-02-07 30 views
0

我想在mapReduce之后填充字段。如何使用Mongoose.js填充mapReduce之后的字段?

mongoose.connection.db.collection('createdCollectionNameForResults', function(err, collection) { 
    collection.find({}).populate('ref_field').toArray(function(err, items) { 
      res.send(200, items) 
    }); 
}); 

但在这里,它提供了错误:

类型错误:对象#有没有方法 '填充'

因为collection.find({})返回MongoDB的光标。我如何填充ref_field?

+0

你调用'在本地驱动程序收集find'。您需要在Mongoose模型上调用'find'来使'populate'工作。 – JohnnyHK

+0

是的,但我应该怎么做? – Burak

+0

为您的集合创建一个模式和模型,您的mapReduce创建,然后像任何其他猫鼬模型一样查询它。请参阅[docs](http://mongoosejs.com/docs/populate.html)。 – JohnnyHK

回答

1

考虑,你有猫鼬注册的模式命名为“createdCollectionNameForResults”

var Model = mongoose.model('createdCollectionNameForResults'); 
Model.find({}).populate('ref_field').exec(function(err, results){ 
    console.log(err, results); 
});