router.get('/programs/:url', (req, res) => {
var url = req.params.url;
var query = {}
query['url']=url;
query['active'] = true;
ProgramModel.aggregate([
{ $match: query },
{ $lookup: { from: "episode", // collection name in db
localField: "_id",
foreignField: "show_id",
as: "episode"
}
},
{ $sort: { _id: -1 } }]).exec(function(err, programs) {
if (!err){
res.status(200).json({
programs
})
//process.exit();
} else {throw err;}
// students contain WorksnapsTimeEntries
});
// res.status(200).json({
// message: "You're authorized to see to edit pages.",
// user values passed through from auth middleware
//user: req.user
// });
});
我在让ProgramModel加入我的节目集和剧集集合时遇到问题。
基本上我需要先打电话给show collection
http://www.example.com/api/programs/showname
我得到的错误是
/root/react-passport-example/node_modules/mongodb/lib/utils.js:123
process.nextTick(function() { throw err; });
^
MongoError: The 'cursor' option is required, except for aggregate with the explain argument
at Function.MongoError.create (/root/react-passport-example/node_modules/mongodb-core/lib/error.js:31:11)
at /root/react-passport-example/node_modules/mongodb-core/lib/connection/pool.js:497:72
at authenticateStragglers (/root/react-passport-example/node_modules/mongodb-core/lib/connection/pool.js:443:16) at Connection.messageHandler (/root/react-passport-example/node_modules/mongodb-core/lib/connection/pool.js:477:5) at Socket.<anonymous> (/root/react-passport-example/node_modules/mongodb-core/lib/connection/connection.js:321:22) at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:607:20)
我该如何使用它?我尝试运行的查询如下:
db.getCollection('shows').aggregate([
{ $match: { _id: ObjectId("5d622cecbbe890f60ccd1ca4") } },
{ $lookup: { from: "episode", // collection name in db
localField: "_id",
foreignField: "show_id",
as: "episode"
}
},
{ $sort: { total: -1 } }
])
版本 “猫鼬”:“ ^ 4.10.4”,
MongoDB 4.0.10