什么参数传递给Mongoose回调 [英] What parameters are passed to Mongoose callbacks

查看:37
本文介绍了什么参数传递给Mongoose回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

猫鼬文档中,它经常列出某些查询运算符的可选回调(例如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?

此外,如果conditionsupdate等是可选的,并且我想在末尾指定一个回调,我是否必须传递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()

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: For findOne() 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆