Return results mongoose in find query to a variable

前端 未结 4 611
再見小時候
再見小時候 2020-12-12 15:39

I need to return the results of a query with mongoose in node.js.

How do you return the value to set the value to a variable?

What I need to do is:

4条回答
  •  孤城傲影
    2020-12-12 16:18

    It is being executed before the assignment.

     async function(req, res) {
          var user;
          await users.findOne({}, function(err,pro){
              user=pro;
            });
          console.log(user); \\ it's define
        };
    

提交回复
热议问题