在 mongoose documentation它经常列出某些查询运算符的可选回调(如 findOneAndUpdate
),但是,它没有提及回调采用哪些参数(参数)。它们是什么,我该如何发现?
另外,如果 conditions
、update
等是可选的,我想在最后指定一个回调,是否必须传入 null
值,或者空对象,或者我可以只指定回调 - Mongoose 知道软管吗?
Model.findOneAndUpdate([conditions], [update], [options], [callback])
最佳答案
对于几乎所有 mongoose queries提供的 callback
函数将使用 node callback pattern 中的两个参数调用callback(err, results)
如文档中所述:
Anywhere a callback is passed to a query in Mongoose, the callback follows the pattern
callback(error, results)
. What results is depends on the operation: ForfindOne()
it is a potentially-null single document,find()
a list of documents,count()
the number of documents,update()
the number of documents affected, etc. The API docs for Models provide more detail on what is passed to the callbacks.
关于node.js - 什么参数被传递给 Mongoose 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29558418/