使用 .exec 和不使用 .exec 的查询有什么区别?
What is the difference of a query with .exec and without?
我声明下一个查询:
const User = await User.findOne().and([{
"accounts.email": re.body.email
},{
status: 1
}])
如果在查询末尾添加.exec()
有什么区别?
就功能而言,将 .exec()
添加到 async/await
查询不会有什么不同。
但是根据 mongoose 文档,您“应该”使用 .exec()
,因为它将为您提供更好的堆栈跟踪。
检查 - Should You Use exec() With await?
Without exec()
, the stack trace does not include the calling code.
With exec()
, the stack trace includes where in your code you called exec()
我声明下一个查询:
const User = await User.findOne().and([{
"accounts.email": re.body.email
},{
status: 1
}])
如果在查询末尾添加.exec()
有什么区别?
就功能而言,将 .exec()
添加到 async/await
查询不会有什么不同。
但是根据 mongoose 文档,您“应该”使用 .exec()
,因为它将为您提供更好的堆栈跟踪。
检查 - Should You Use exec() With await?
Without
exec()
, the stack trace does not include the calling code.
With
exec()
, the stack trace includes where in your code you calledexec()