在回调中使用lean in mongoose [英] Use lean in mongoose with callback

查看:118
本文介绍了在回调中使用lean in mongoose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的mongoDB查询中使用lean,但是我面临的问题是我不使用.exec()方法,我使用了如下的回调实现

I am trying to use lean in my mongoDB query but the problem i am facing is that i don't use .exec() method, i use callback implementation like below

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 {

     }
});

但是无论我在哪里有文档,每个人都将.exec()与精益结合使用,如下所示

but wherever i have documentation everyone use lean with .exec() like below

.lean().exec()

谁能告诉我如何使用我的回调实现来使用精益,否则我将不得不在ordr中使用.exec()实现来使用它.

Can anyone please tell me how can i use lean using my callback implementation or i would have to use .exec() implementation in ordr to use it.

推荐答案

您可以同时使用.exec()和回调:

You can use both .exec() and callbacks:

model.find(...).lean().exec(function(err, docs) {
  ...
});

另请参见文档,其中一个示例执行的操作相同

See also the documentation, where one of the examples does the same.

这篇关于在回调中使用lean in mongoose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆