var o = {};
o.query = { 'place' : req.param('place') ,
'_id' : {'$nin':req.user.ratings}
}
o.map = function () { emit(0, {k: this, v: Math.random()}) }
o.reduce = function(k, v) {
var a = []
v.forEach(function(x) {
a = a.concat(x.a ? x.a : x)
})
return {a:a.sort(function(a, b) {
return a.v - b.v;
}).slice(0, 10 /*how many records you want*/)};
}
o.finalize = function(k, v) {
return v.a.map(function(x) {
return x.k
})
}
o.out = { replace: 'createdCollectionNameForResults' };
Venue.mapReduce(o, function (err, results) {
mongoose.connection.db.collection('createdCollectionNameForResults', function(err, collection) { //query the new map-reduced table
collection.find({}).populate('place').toArray(function(err, pings) { //only pull in the top 10 results and sort descending by number of pings
res.send(200, pings)
});
});
})
But I am getting TypeError because collection.find({}) is from MongoDB, not from Mongoose. How can I populate references?