Sets or gets the default captureRejection value for all emitters.设置或获取所有发射器的默认captureRejection
值。
This symbol shall be used to install a listener for only monitoring 此符号应用于安装仅用于监视'error'
events. 'error'
事件的侦听器。Listeners installed using this symbol are called before the regular 使用此符号安装的侦听器在调用常规'error'
listeners are called.'error'
侦听器之前被调用。
Installing a listener using this symbol does not change the behavior once an 使用此符号安装侦听器不会在发出'error'
event is emitted, therefore the process will still crash if no regular 'error'
listener is installed.'error'
事件后改变行为,因此如果没有安装常规的'error'
侦听器,进程仍将崩溃。
Connect to MongoDB using a url使用url连接到MongoDB
Create a new Db instance sharing the current socket connections.创建一个共享当前套接字连接的新Db实例。
The name of the database we want to use. 我们要使用的数据库的名称。If not provided, use database name from connection string.如果未提供,请使用连接字符串中的数据库名称。
Optional settings for Db constructionDb构造的可选设置
Return the mongo client logger返回mongo客户端记录器
Starts a new session on the server在服务器上启动新会话
Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this cluster. 创建一个新的更改流,监视此集群中的新更改(插入、更新、替换、删除和无效)。Will ignore all changes to system collections, as well as the local, admin, and config databases.将忽略对系统集合以及本地、管理和配置数据库的所有更改。
Type of the data being detected by the change stream更改流检测到的数据类型
Type of the whole change stream document emitted发出的整个变更流文档的类型
An array of aggregation pipeline stages through which to pass change stream documents. 一组聚合管道阶段,用于传递更改流文档。This allows for filtering (using $match) and manipulating the change stream documents.这允许筛选(使用$match
)和操作变更流文档。
Optional settings for the command命令的可选设置
Runs a given operation with an implicitly created session. 使用隐式创建的会话运行给定操作。The lifetime of the session will be handled without the need for user interaction.会话的生存期将在不需要用户交互的情况下处理。
NOTE: presently the operation MUST return a Promise (either explicit or implicitly as an async function)注意:当前操作必须返回Promise(作为异步函数显式或隐式)
An callback to execute with an implicitly created session使用隐式创建的会话执行的回调
Connect to MongoDB using a url使用url连接到MongoDB
Returns a copy of the array of listeners for the event named 返回名为eventName
.eventName
的事件的侦听器数组的副本。
For 对于EventEmitter
s this behaves exactly the same as calling .listeners
on the emitter
.EventEmitter
,这与调用emitter
上的.listeners
完全相同。
For 对于EventTarget
s this is the only way to get the event listeners for the event target. EventTarget
,这是获取事件目标的事件侦听器的唯一方法。This is useful for debugging and diagnostic purposes.这对于调试和诊断非常有用。
const { getEventListeners, EventEmitter } = require('events');
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
getEventListeners(ee, 'foo'); // [listener]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
getEventListeners(et, 'foo'); // [listener]
}
A class method that returns the number of listeners for the given 返回在给定eventName
registered on the given emitter
.emitter
上注册的给定eventName
的侦听器数量的类方法。
const { EventEmitter, listenerCount } = require('events');
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
The emitter to query要查询的发射器
The event name事件名称
```js const { on, EventEmitter } = require('events');
(async () => { const ee = new EventEmitter();
// Emit later on process.nextTick(() => { ee.emit('foo', 'bar'); ee.emit('foo', 42); });
for await (const event of on(ee, 'foo')) { // The execution of this inner block is synchronous and it // processes one event at a time (even with await). Do not use // if concurrent execution is required. console.log(event); // prints ['bar'] [42] } // Unreachable here })();
Returns an `AsyncIterator` that iterates `eventName` events. It will throw
if the `EventEmitter` emits `'error'`. It removes all listeners when
exiting the loop. The `value` returned by each iteration is an array
composed of the emitted event arguments.
An `AbortSignal` can be used to cancel waiting on events:
```js
const { on, EventEmitter } = require('events');
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
The name of the event being listened for正在侦听的事件的名称
that iterates eventName
events emitted by the emitter
Creates a Promise
that is fulfilled when the EventEmitter
emits the given event or that is rejected if the EventEmitter
emits 'error'
while waiting. The Promise
will resolve with an array of all the arguments emitted to the given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event semantics and does not listen to the 'error'
event.
const { once, EventEmitter } = require('events');
async function run() {
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.log('error happened', err);
}
}
run();
The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the 'error'
event itself, then it is treated as any other kind of event without special handling:
const { EventEmitter, once } = require('events');
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.log('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
An AbortSignal
can be used to cancel waiting for the event:
const { EventEmitter, once } = require('events');
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
```js const { setMaxListeners, EventEmitter } = require('events');
const target = new EventTarget(); const emitter = new EventEmitter();
setMaxListeners(5, target, emitter); ```
A non-negative number. 非负数。The maximum number of listeners per 每个EventTarget
event.EventTarget
事件的最大侦听器数。
Generated using TypeDoc
The MongoClient class is a class that allows for making Connections to MongoDB.MongoClient
类是一个允许连接到MongoDB的类。The programmatically provided options take precedence over the URI options.编程提供的选项优先于URI选项。