node.js - 什么参数被传递给 Mongoose 回调

标签 node.js mongodb mongoose

mongoose documentation它经常列出某些查询运算符的可选回调(如 findOneAndUpdate),但是,它没有提及回调采用哪些参数(参数)。它们是什么,我该如何发现?

另外,如果 conditionsupdate 等是可选的,我想在最后指定一个回调,是否必须传入 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: 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.

关于node.js - 什么参数被传递给 Mongoose 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29558418/

相关文章:

javascript - 仅在有条件时才绘制 Lodash map

javascript - rijndael-128 cbc javascript 不像 php mcrypt 那样返回正确

json - 无法从 JSON 对象中删除字段 - Node JS

mongodb - 在spring中使用嵌入式mongo仅用于本地测试

java - Nutch Crawler错误:Hadoop路径权限

javascript - 如何在socket.io中获取特定的cookie值

java - 使用模拟更新列表时出现 StackOverflowError

javascript - 向对象 Mongoose 方式添加字段

javascript - Mongoose 具有相同的保存和更新中间件功能

node.js - 根据数组元素查找对象,只返回匹配的数组元素?