我正尝试在mongoDB查询中使用lean,但是我面临的问题是我没有使用.exec()方法。我使用的回调实现如下
model.find({user_id: mobile_no }, {'_id':0, 'type':1}, {sort: {dateTime: -1}, skip: page*page_size, limit: page_size + 1}, function(err, docs) {
if (err) {
} else {
}
});但在大多数文档中,每个人都将lean与.exec()结合使用,如下所示
.lean().exec()谁能告诉我如何通过我的回调实现使用lean,否则我必须使用.exec()实现才能使用它。
发布于 2017-05-15 17:47:14
您可以同时使用.exec()和回调:
model.find(...).lean().exec(function(err, docs) {
...
});另请参阅the documentation,其中一个示例执行相同的操作。
发布于 2018-08-10 20:59:00
model.find({user_id: mobile_no }, {'_id':0, 'type':1}, {sort: {dateTime: -1}, skip: page*page_size, limit: page_size + 1}, function(err, docs) {
if (err) {
} else {
}
}).lean();您必须在查询的末尾编写.lean() :3
https://stackoverflow.com/questions/43974330
复制相似问题