什么参数传递给Mongoose回调 [英] What parameters are passed to Mongoose callbacks
问题描述
在猫鼬文档中,它经常列出某些查询运算符的可选回调(例如findOneAndUpdate
),但是它没有提到回调采用什么参数(参数).他们是什么,我怎么知道?
In the mongoose documentation it frequently lists an optional callback for certain query operators (like findOneAndUpdate
), however, it does not mention what parameters (arguments) the callback takes. What are they, and how would I find out?
此外,如果conditions
,update
等是可选的,并且我想在末尾指定一个回调,我是否必须传递null
值或空对象,还是可以仅指定回调-猫鼬知道软管吗?
Also, if conditions
, update
etc. are optional, and I want to specify a callback at the end, do I have to pass in the null
value, or empty objects or can I just specify the callback -- and hose does Mongoose know?
Model.findOneAndUpdate([conditions], [update], [options], [callback])
推荐答案
几乎所有猫鼬查询提供的callback
函数将在节点回调模式 callback(err, results)
如文档中所述:
For nearly all mongoose queries the provided callback
function will be called with two arguments in the node callback pattern callback(err, results)
as stated in the documentation:
在Mongoose中将回调传递给查询的任何地方,回调都遵循模式
callback(error, results)
.结果取决于操作:对于findOne()
,它是可能为空的单个文档,find()
文档列表,count()
文档数,update()
用于模型的API文档提供了有关传递给回调的内容的详细信息.
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.
这篇关于什么参数传递给Mongoose回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!