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

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

问题描述

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 值,或空对象,或者我可以只指定回调 - Mongoose 知道吗?

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])

推荐答案

几乎所有 mongoose 查询 提供的 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() a 文档列表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: 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天全站免登陆