Mongoose 等待投猫鼬查询如何承诺?

Mongoose 等待投猫鼬查询如何承诺?,mongoose,async-await,Mongoose,Async Await,我错过了mongoose查询的exec()函数调用,然后节点应用程序获得了较高的CPU利用率。在chrome profiler中,我看到mongoose反序列化函数调用占总使用量的35%。有谁能解释一下在等待投下这一模式的承诺时会发生什么 //Many deserialize calls and high CPU usage let messages = await Models.Message.find({}); //All fine! messages = await Models

我错过了mongoose查询的exec()函数调用,然后节点应用程序获得了较高的CPU利用率。在chrome profiler中,我看到mongoose反序列化函数调用占总使用量的35%。有谁能解释一下在等待投下这一模式的承诺时会发生什么

//Many deserialize calls and high CPU usage
let messages = await Models.Message.find({});    

//All fine!
messages = await Models.Message.find({}).exec();  

Mongoose查询模型是。就我而言

  • 等待使用承诺.解决()强制转换对象
  • 然后Promise.resolve调用对象的Then()函数
  • then()函数返回Promise
  • 我看,要把目标变成承诺是如此昂贵

    /***执行查询,返回一个
    承诺
    ,该承诺将* 已通过文档解决,或因错误而被拒绝。** @param{Function}[resolve]*@param{Function}[reject]*@return {Promise}*@api public*/

    Query.prototype.then = function(resolve, reject) {
      return this.exec().then(resolve, reject);
    };