Mongoose :函数 "once"

标签 mongoose

在 Mongoose ( http://mongoosejs.com/docs/index.html ) 的“入门”中有一个使用函数 once 的示例。 :

db.once('open', function callback () {
  // yay!
});

但在官方文档中我没有找到任何对函数 once 的引用( http://mongoosejs.com/docs/api.html )。

这个函数的意义是什么?

最佳答案

Mongoose 连接是 EventEmitter class 的一个实例.从文档:

Adds a one time listener for the event. This listener is invoked only the next time the event is fired, after which it is removed.

关于 Mongoose :函数 "once",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17575300/

相关文章:

node.js - 如何在nodejs中使用objectId

javascript - mongoose 检查 id 是否存在,但该 id 嵌套在数组中

node.js - Mongoose Populate Virtuals 不起作用并返回 null

javascript - 为什么这个函数表达式未定义?

javascript - 如何从 Mongo 中的数组中删除元素

javascript - .sort() 根本不工作( Mongoose )

MongoDB Lookup 仅当没有数据时返回空数组

node.js - Pro.find is not a function error in mongoose 模型导出

javascript - mongoose/mongodb 查询从 javascript 数组中的每个发件人获取最后一个文档

mongoose - 将 bluebird 与 mongoose 一起使用的正确方法是什么?