更新时间:2023-11-26 10:41:22
第二个参数用于选择字段.您需要在第三个参数中添加选项:
The second parameter is for the fields to select. You need to add options to the third parameter:
posts.find({'creator.user_id': req.params.user_id}, null, {sort: {'_id': -1}}, function(err,userpost) {
if(err)
res.send(err);
res.json(userpost);
});
或者,您可以使用sort()
函数:
Alternatively you can use the sort()
function:
posts.find({'creator.user_id': req.params.user_id}).sort({'_id': -1}).exec(function(err,userpost) {
if(err)
res.send(err);
res.json(userpost);
});
您可以在文档中找到更多示例.
You can find more examples in the documentation.