OptionalawaitOptionalreadOptionalsession?: ClientSessionOptionaltailable?: booleanOptional Experimentaltimeoutconst cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
for await (const doc of cursor) {
// process doc
// This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
// will continue to iterate successfully otherwise, regardless of the number of batches.
}
const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
Optional ExperimentaltimeoutMS?: numberSpecifies the time an operation will run until it throws a timeout error. 指定操作运行到抛出超时错误的时间。Note that if 请注意,如果命令中除了在选项中设置maxTimeMS is provided in the command in addition to setting timeoutMS in the options, then the original value of maxTimeMS will be overwritten.timeoutMS外还提供了maxTimeMS,则maxTimeMS的原始值将被覆盖。
Specifies how指定如何将timeoutMSis applied to the cursor.timeoutMS应用于游标。Can be either可以是'cursorLifeTime'or'iteration'When set to'iteration', the deadline specified bytimeoutMSapplies to each call ofcursor.next().'cursorLifeTime'或'iteration'。当设置为'iteration'时,timeoutMS指定的截止日期适用于每次调用cursor.next()。When set to当设置为'cursorLifetime', the deadline applies to the life of the entire cursor.'cursorLifetime'时,截止日期适用于整个游标的生命周期。Depending on the type of cursor being used, this option has different default values.根据所使用的游标类型,此选项具有不同的默认值。For non-tailable cursors, this value defaults to对于不可尾随的游标,此值默认为'cursorLifetime'For tailable cursors, this value defaults to'iteration'since tailable cursors, by definition can have an arbitrarily long lifetime.'cursorLifetime'。对于可尾随游标,此值默认为'iteration',因为根据定义,可尾随游标可以具有任意长的生存期。