MongoClient类
创建对MongoDB的连接
构造函数
new MongoClient(url, options?)
参数 | 类型 | 必要性 | 说明 |
---|---|---|---|
url | 字符串 | 必要的 | 连接字符串 |
options | 对象 | 可选的 |
options的内容(MongoClientOptions类的实例)
子项 | 类型 | 说明 |
---|---|---|
ALPNProtocols | string[] | Uint8Array | Uint8Array[] | 字符串数组或缓冲区,命名可能的ALPN协议。 (协议应按优先级排序。) |
appName | string | 创建此MongoClient实例的应用程序的名称。 |
auth | object: Auth | 连接到服务器时的身份验证设置。包含username 和password 两个参数 |
authMechanism | object: AuthMechanism | 指定MongoDB将用于对连接进行身份验证的身份验证机制。 |
authMechanismProperties | object: AuthMechanismProperties | 将指定authMechanism 的属性指定为逗号分隔的键值对列表。 |
authSource | string | 指定与用户凭据关联的数据库名称。 |
autoEncryption | object: AutoEncryptionOptions | 可选地启用使用中的自动加密 |
bsonRegExp | boolean | 将BSON正则表达式作为BSONRegExp 实例返回。 |
ca | string | Buffer | (string | Buffer)[] | 覆盖受信任的CA证书。默认情况是信任Mozilla策划的知名CA。当使用此选项显式指定CA时,Mozilla的CA将被完全替换。 |
cert | string | Buffer | (string | Buffer)[] | PEM格式的证书链。每个私钥应提供一个证书链。 |
checkKeys | boolean | 序列化程序将检查键是否有效。 |
checkServerIdentity | 函数 | 参数为(hostname, cert) ,返回Error|undefined 验证证书 cert 是否颁发给hostname 。 |
ciphers | string | 密码套件规范,替换默认规范。 |
compressors | string | ("none" | "snappy" | "zlib" | "zstd")[] | 压缩器的数组或逗号分隔字符串,用于为此客户端和mongod /mongos 实例之间的通信启用网络压缩。 |
connectTimeoutMS | number | 超时前尝试连接的时间(以毫秒为单位)。 |
directConnection | boolean | 允许驱动程序强制使用包含一个主机的连接字符串的单一拓扑类型 |
driverInfo | object: DriverInfo | 允许包装驱动程序修改驱动程序生成的客户端元数据,以包含有关包装驱动程序的信息 |
ecdhCurve | string | 描述命名曲线或曲线NID或名称的冒号分隔列表的字符串,例如P-521:P-384:P-256,用于ECDH键协商。 |
enableUtf8Validation | boolean | 在反序列化BSON文档时启用utf8验证。默认为true 。 |
family | number | |
fieldsAsRaw | Document | 指定希望返回哪些字段作为未序列化的原始缓冲区。 |
forceServerObjectId | boolean | 强一致性务器分配_id 值而不是驱动程序 |
heartbeatFrequencyMS | number | 控制驱动程序每两次检查MongoDB部署的状态之间时间间隔(以毫秒为单位)。 |
hints | number | |
ignoreUndefined | boolean | 默认为true 。如果驱动程序将其设置为false ,则序列化不会发出未定义的字段备注 |
key | string | Buffer | (string | Buffer | KeyObject)[] | PEM格式的私钥。 |
loadBalanced | boolean | 指示驱动程序是否连接到面向mongos 类服务的负载平衡器 |
localAddress | string | |
localPort | number | |
localThresholdMS | number | 用于在多个合适的MongoDB实例中进行选择的延迟窗口的大小(以毫秒为单位)。 |
lookup | 函数 | |
maxConnecting | number | 连接池可能同时建立的最大连接数。 |
maxIdleTimeMS | number | 在删除和关闭连接之前,连接在池中可以保持空闲的最大毫秒数。 |
maxPoolSize | number | 连接池中的最大连接数。 |
maxStalenessSeconds | number | 以秒为单位指定在客户端停止使用辅助进行读取操作之前,辅助的过时程度。 |
minDHSize | number | |
minHeartbeatFrequencyMS | number | 设置最小检测信号频率。如果驱动程序必须频繁地重新检查服务器的可用性,它将在上次检查后至少等待这么长时间,以避免浪费精力。 |
minPoolSize | number | 连接池中的最小连接数。 |
monitorCommands | boolean | 对此客户端启用命令监视 |
noDelay | boolean | TCP连接无延迟 |
passphrase | string | 用于单个私钥和/或PFX的共享密码短语。 |
pfx | string | Buffer | (string | Buffer | PxfObject)[] | PFX或PKCS12编码的私钥和证书链。 |
pkFactory | object: PkFactory | 用于生成自定义_id 键的主键工厂函数 |
promoteBuffers | boolean | 当反序列化Binary时,它将作为node.js Buffer实例返回。 |
promoteLongs | boolean | 当反序列化Long时,如果它小于53位,则将其放入Number中。 |
promoteValues | boolean | 反序列化时将BSON值提升为其Node.js最接近的等效类型。 |
proxyHost | string | 配置用于创建TCP连接的Socks5代理主机。 |
proxyPassword | string | 当proxyHost中的代理需要用户名/密码身份验证时,配置Socks5代理密码。 |
proxyPort | number | 配置用于创建TCP连接的Socks5代理端口。 |
proxyUsername | string | 当proxyHost中的代理需要用户名/密码身份验证时,配置Socks5代理用户名。 |
raw | boolean | 启用raw选项将返回使用allocUnsafe API分配的Node.js缓冲区。 |
readConcern | ReadPreference | ReadConcernLike | 指定集合的读取关注 |
readConcernLevel | enum: ReadConcernLevel | 隔离级别 |
readPreference | enum: ReadPreferenceMode | 指定此连接的读取首选项 |
readPreferenceTags | TagSet[] | 将标记文档指定为逗号分隔的键值对列表。 |
rejectUnauthorized | boolean | 如果为true ,则服务器将拒绝未经所提供CA列表授权的任何连接。只有当requestCert 为true 时,此选项才有效。 |
replicaSet | string | 如果mongod 是副本集的成员,则指定副本集的名称。 |
retryReads | boolean | 启用可重试读取。 |
retryWrites | boolean | 启用可重试写入。 |
secureContext | object: secureContext | tls.createSecureContext() 中的可选TLS上下文对象 |
secureProtocol | string | 传统机制选择TLS协议版本使用 |
serializeFunctions | boolean | 是否序列化javascript函数。默认值false |
serverApi | "1" | ServerApi | Server API version |
serverSelectionTimeoutMS | number | 指定在引发异常之前阻止服务器选择的时间(以毫秒为单位)。 |
servername | string | 服务器名称 |
session | Buffer | 包含TLS会话的可选缓冲区实例。 |
socketTimeoutMS | number | 在尝试超时之前,在套接字上尝试发送或接收的时间(以毫秒为单位)。 |
srvMaxHosts | number | 使用srv连接字符串时要连接到的最大主机数,设置为0 表示主机不受限制 |
srvServiceName | string | 修改srv URI,使其看起来像:_{srvServiceName}._tcp.{hostname}.{domainname} |
ssl | boolean | 用于为连接启用或禁用TLS/SSL的布尔值。 |
tls | boolean | 为连接启用或禁用TLS/SSL。 |
tlsAllowInvalidCertificates | boolean | 绕过mongod/mongos实例提供的证书验证 |
tlsAllowInvalidHostnames | boolean | 禁用mongod/mongos实例提供的证书的主机名验证。 |
tlsCAFile | string | 指定本地pem文件的位置,该文件包含来自证书颁发机构的根证书链。此文件用于验证mongod/mongos实例提供的证书。 |
tlsCRLFile | string | 指定包含客户端吊销列表的本地CRL pem文件的位置。 |
tlsCertificateKeyFile | string | 指定本地.pem文件的位置,该文件包含客户端的TLS/SSL证书和键。 |
tlsCertificateKeyFilePassword | string | 指定对tlsCertificateKeyFile 进行解密的密码。 |
tlsInsecure | boolean | 禁用各种证书验证。 |
useBigInt64 | boolean | 当将Long返回反序列化为BigInt时。 |
waitQueueTimeoutMS | number | 线程可以等待连接可用的最长时间(以毫秒为单位)。 |
writeConcern | WriteConcern | WriteConcernSettings | MongoDB针对写入操作请求的确认级别。 |
zlibCompressionLevel | number | 如果使用zlib进行网络压缩,则指定压缩级别的整数。 |
静态属性
静态属性 | 类型 | 读写性 | 说明 |
---|---|---|---|
captureRejectionSymbol | captureRejectionSymbol | 只读 | |
captureRejections | booean | 读写 | 设置或获取所有发射器的默认captureRejection 值。 |
defaultMaxListeners | number | 读写 | |
errorMonitor | errorMonitor | 只读 | 安装仅用于监视'error' 事件的侦听器。 |
访问器
访问器 | 返回类型 | 说明 |
---|---|---|
get bsonOptions | BSONSerializeOptions | 返回BSON序列化选项。 |
set monitorCommands(value:boolean) | void | |
get options | MongoOptions | |
get readConcern | REadPreference | |
get readPreference | undefined | ReadConcern | |
get serverApi | undefined | ServerApi | |
get writeConcern | undefined | WriteConcern |
实例方法
方法 | 返回类型 | 说明 |
---|---|---|
addListener(eventName,listener) | MongoClient | eventName的值可以是"error" | "timeout" | "close" | "open" | "serverOpening" | "serverClosed" | "serverDescriptionChanged" | "topologyOpening" | "topologyClosed" | "topologyDescriptionChanged" | "connectionPoolCreated" | "connectionPoolClosed" | "connectionPoolCleared" | "connectionPoolReady" | "connectionCreated" | "connectionReady" | "connectionClosed" | "connectionCheckOutStarted" | "connectionCheckOutFailed" | "connectionCheckedOut" | "connectionCheckedIn" | "commandStarted" | "commandSucceeded" | "commandFailed" | "serverHeartbeatStarted" | "serverHeartbeatSucceeded" | "serverHeartbeatFailed"。listener是一个参数为event的函数。 |
removeListener(eventName,listener) | MongoClient | 参数同上 |
removeAllListener(eventName?) | MongoClient | |
close(force?) | Promise<void> | 关闭客户端及其基础连接。如果参数force 是true ,则强制关闭,不发出任何事件。 |
connect() | Promise<MongoClient> | 没有参数。使用url连接到MongoDB |
db(dbName?, options?) | Db | 创建共享当前套接字连接的新Db 实例。可选的options参数是DbOptions类的实例 |
emit(event,...args) | boolean | 激发某某事件并给事件处理函数传入相关参数 |
events() | string[] | 返回事件名列表 |
getMaxListeners() | number | |
listenerCount(eventName) | number | |
listeners(eventName) | listener[] | |
on(eventName,listener) | MongoClient | 同addListener |
off(eventName,listener) | MongoClient | 同removeListener |
once(eventName, listener) | MongoClient | 同addListener ,但是只激发一次就删除 |
prependListener(event, listener) | MongoClient | 同addListener ,但是按相反的顺序调用事件函数 |
prependOnceListener(event, listener) | MongoClient | 同addListener ,但是按相反的顺序调用事件函数,而且只激发一次就删除 |
rawListeners(eventName) | listener[] | |
setMaxListeners(n) | MongoClient | |
startSession(options?) | ClientSession | 创建新的ClientSession 。在操作中使用返回的会话时,将创建相应的ServerSession 。可选的options参数是ClientSessionOptions类的实例。 |
watch(pipeline?, options?) | ChangeStream<TSchema, TChange> | 创建一个新的变更流,监视此群集中的新变更(插入、更新、替换、删除和无效)。将忽略对系统集合以及本地、管理和配置数据库的所有更改。可选的options参数是ChangeStreamOptions类的实例。 |
withSession(executor) | Promise<T> | 创建和处理ClientSession 清理的一种方便方法。会话将始终在executor 完成时结束。 |
静态方法
方法 | 返回类型 | 说明 |
---|---|---|
connect(url, options?) | MongoClient | 使用url连接到MongoDB。可选的options参数是MongoClientOptions的实例。 |
getEventListeners(emitter, eventName) | Function[] | 返回名为eventName 的事件的侦听器数组的副本。 |
listenerCount(emitter, eventName) | number | 返回在给定emitter 上注册的给定eventName 的侦听器数。 |
on(emitter, eventNamme, options?) | AsyncIterableIterator<any> | 可选的options参数是StaticEventEmitterOptions类的实例。 |
once(emitter, eventName, options?) | Promise<any[]> | 创建一个Promise,该Promise在EventEmitter 发出给定事件时实现,或者如果EventEmitter 在等待时发出'error' 则被拒绝。 Promise将通过向给定事件发出的所有参数的数组进行解析。可选的options参数是StaticEventEmitterOptions类的实例。 |
setMaxListeners(n?,...eventTargets) | void |
ClientSession类
构造函数
无法用构造器实例化,用MongoClient.startSession(options?)
来实例化。
options的内容(ClientSessionOptions类的实例)
子项 | 类型 | 说明 |
---|---|---|
causalConsistency | boolean | 是否应在此会话上启用因果一致性 |
defaultTransactionOptions | TransactionOptions | 用于此会话上启动的事务的默认TransactionOptions 。 |
snapshot | boolean | 是否应从此会话的同一快照读取所有读取操作(注意:与causalConsistency=true不兼容) |
实例属性
属性 | 类型 | 说明 |
---|---|---|
clientOptions | MongoOptions | |
clusterTime | clusterTime | |
defaultTransactionOption | TransactionOptions | |
explicit | boolean | |
hasEnd | boolean | |
operationTime | Timestamp | |
support | {causalConsistency:boolean} | |
transaction | Transaction |
实例属性
属性 | 类型 | 说明 |
---|---|---|
captureRejectionSymbol | captureRejectionSymbol | 只读 |
captureRejections | boolean | 设置或获取所有发射器的默认captureRejection 值。 |
defaultMaxListeners | number | |
errorMonitor | errorMontor | 用于安装仅用于监视'error' 事件的侦听器。 |
访问器
访问器 | 返回类型 | 说明 |
---|---|---|
get id | undefined | ServerSessionId | 与此会话关联的服务器id |
get isPinned | boolean | |
get loadBalanced/code> | boolean | |
get serverSession | ServerSession | |
get snapshotEnabled | boolean | 是否为此会话配置快照读取 |
实例方法
方法 | 返回类型 | 说明 |
---|---|---|
snapshotEnabled() | boolean | 中止此会话中当前活动的事务。 |
addListener(eventName, listener) | ClientSession | |
advanceClusterTime(clusterTime) | void | |
commitTransaction() | Promise<void> | 提交此会话中当前活动的事务。 |
emit(event,...args) | boolean | |
endSession(options?) | Promise<void> | 在服务器上结束此会话。可选的options参数是EndSessionOptions类的实例 |
equals(session) | boolean | 用于确定此会话是否等于另一个会话 |
eventNames | string[] | |
getMaxListeners() | number | |
inTransaction() | boolean | 此会话当前是否在事务中 |
incrementTransactionNumber() | void | 增加内部ServerSession 上的事务编号 |
listenerCount(type) | number | |
listeners(eventName) | ClientSessionEvents[EventKey][] | |
on(eventName, listener) | ClientSession | |
off(eventName, listener) | ClientSession | |
once(eventName, listener) | ClientSession | |
prependListener(eventName, listener) | ClientSession | |
prependOnceListener(eventName, listener) | ClientSession | |
rawListeners(eventKey) | ClientSessionEvents[EventKey][] | |
removeListener(eventName, listener) | ClientSession | |
removeAllListeners(eventName?) | ClientSession | |
setMaxListeners(n) | ClientSession | |
startTransaction(options) | void | 使用给定选项启动新事务。 |
toBSON() | never | 这是为了确保ClientSession 永远不会序列化到BSON。 |
withTransaction(fn, options?) | Promise<T> | 启动事务并运行提供的函数,确保在函数中运行的所有操作完成后始终尝试commitTransaction 。可选的options参数是TransactionOptions类的实例。 |
Db类
构造函数
可以使用构造函数来实例化,也可以使用MongoClient.db(dbName?, options?)
来实例化。构造函数:new Db(client, dbName, options?)
。
options的内容(DbOptions类的实例)
子项 | 类型 | 说明 |
---|---|---|
authSource | string | 如果数据库身份验证依赖于另一个数据库名称。 |
bsonRegExp | boolean | 将BSON正则表达式作为BSONRegExp实例返回。 |
checkKeys | boolean | 序列化程序将检查键是否有效。 |
enableUtf8Validation | boolean | 在反序列化BSON文档时启用utf8验证。 |
fieldsAsRaw | Document | 指定我们希望返回哪些字段作为未序列化的原始缓冲区 |
forceServerObjectId | boolean | 强一致性务器分配_id 值而不是驱动程序。 |
ignoreUndefined | boolean | 如果驱动程序将其设置为false ,则序列化将不会发出未定义的字段备注。 |
pkFactory | PkFactory | 用于生成自定义_id 键的主键工厂对象。 |
promoteBuffers | boolean | 当反序列化Binary时,它将作为node.js Buffer实例返回。 |
promoteLongs | boolean | 当反序列化Long时,如果它小于53位,则将其放入Number中。 |
promoteValues | boolean | 反序列化时将BSON值提升为其Node.js最接近的等效类型。 |
raw | boolean | 启用raw 选项将返回使用allocUnsafe API分配的Node.js缓冲区。 |
readConcern | ReadConcern | 指定集合的读取关注。 |
readPreference | ReadPreferenceLike | 首选读取首选项 |
retryWrites | boolean | 是否应重试失败的写入 |
serializeFunctions | boolean | 是否序列化javascript函数,默认值为false 。 |
useBigInt64 | boolean | 当将Long返回反序列化为BigInt时。 |
writeConcern | WriteConcern | WriteConcernSettings | 写入关注对象 |
访问器
访问器 | 返回类型 | 说明 |
---|---|---|
get bsonOptions | BSONSerializeOptions | |
get databaseName | string | |
get namespace | string | |
get options | undefined | DbOptions | |
get readConcern | undefined | ReadConcern | |
get readPreference | ReadPreference | Db 的当前readPreference 。如果没有为此Db 明确定义,则将从父MongoClient 继承 |
get secondaryOk | boolean | 检查是否可以使用辅助 |
get writeConcern | undefined | WriteConcern |
实例方法
方法 | 返回类型 | 说明 |
---|---|---|
admin() | admin | 返回Admin数据库实例 |
aggregate(pipeline?, options?) | AggregateCursor<T> | 针对数据库执行聚合框架管道。可选的options参数是AggregateOptions的实例 |
collection(name, options?) | Collection<TSchema> | 返回对MongoDB集合的引用。如果它不存在,它将被隐式创建。可选的options参数是CollectionOptions的实例。 |
collections(options?) | Promise<Collection<Document>[]> | 获取当前数据库的所有集合。可选的options参数是ListCollectionsOptions的实例。 |
commnd(commmand, options?) | Promise<Document> | 执行命令。可选的options参数是RunCommandOptions的实例。 |
createCollection(collName, options?) | Promise<Collection<TSchema<> | 指定的选项在服务器上创建新集合。可选的options参数是CreateCollectionOptions的实例。 |
createindex(indexName, indexSpec, options?) | Promise<string> | 在数据库和集合上创建索引。可选的options参数是createIndexesOptions的实例。 |
dropCollection(name, options) | Promise<boolean> | 从数据库中删除集合,并将其永久删除。可选的options参数是DropCollectionOptions的实例。 |
dropDatabase(options?) | Promise<boolean> | 删除数据库,将其从服务器中永久删除。可选的options参数是CommandOperationOptions的实例。 |
indexInfomation(name, options?) | Promise<Document> | 索引此集合的索引信息。可选的options参数是IndexInformationOptions的实例。 |
listCollections(filter,options?) | ListCollectionsCursor<Pick<CollectionInfo, "type"|"name">> | 使用可选筛选器列出此数据库的所有集合。可选的options参数是ListCollectionsOptions的实例,或者{nameOnly:true} |
profilingLevel(options?) | Promise<string> | 检索MongoDB的当前评测级别。可选的options参数是CommandOperationOptions的实例。 |
removeUser(userName, options?) | Promise<boolean> | 从数据库中删除用户 |
renameCollection(fromCollName,toCollName, options?) | Promise<Collection<TSchema>> | 重命名集合。可选的options参数是RenameOptions的实例。 |
runCursorCommand(command, options) | RunCommandCursor | 提供基本驱动程序功能的低级游标。可选的options参数是RunCursorCommandOptions的实例。 |
setProfilingLevel(level, options?) | Promise<ProfilingLevel> | 设置MongoDB的当前评测级别。可选的options参数是CommandOperationOptions的实例 |
stats(options?) | Promise<Document> | 获取所有数据库统计信息。可选的options参数是DbStatsOptions的实例。 |
watch(pipeline?, options?) | ChangeStream<TSchema, TChange> | 创建一个新的变更流,监视此数据库中的新变更(插入、更新、替换、删除和无效)。将忽略对系统集合的所有更改。可选的options参数是ChangeStreamOptions的实例。 |
Collection类
构造函数
没有构造函数。但是可以用Db.collection(collName, options?)
来实例化。
options的内容(DbOptions类的实例)
子项 | 类型 | 说明 |
---|---|---|
bsonType | boolean | 将BSON正则表达式作为BSONRegExp实例返回。 |
checkKeys | boolean | 序列化程序将检查键是否有效。 |
enableUtf8Validation | boolean | 在反序列化BSON文档时启用utf8验证。默认为true 。 |
fieldsAsRaw | Document | 允许指定我们希望返回哪些字段作为未序列化的原始缓冲区。 |
ignoreUndefined | boolean | 如果驱动程序将其设置为false ,则序列化不会发出未定义的字段备注 |
promoteBuffers | boolean | 当反序列化Binary时,它将作为nodejs Buffer实例返回。 |
promoteLongs | boolean | 当反序列化Long时,如果它小于53位,则将其放入Number中。 |
promoteValues | boolean | 反序列化时将BSON值提升为其Node.js最接近的等效类型。 |
raw | boolean | 启用raw 选项将返回使用allocUnsafe API分配的Node.js缓冲区。 |
readConcern | ReadConcernLike | 指定集合的读取关注。 |
readPreference | ReadPreferenceLike | 首选读取首选项 |
serializeFunctions | boolean | 是否序列化javascript函数,默认值为false 。 |
useBigInt64 | boolean | 当将Long返回反序列化为BigInt时。 |
writeConcern | WriteConcern | WriteConcernSettings | 写入关注对象 |
访问器
访问器 | 返回类型 | 说明 |
---|---|---|
get bsonOptions | BSONSerializeOptions | |
get collectionName | string | 此集合的名称 |
get dbName | string | 此集合所属数据库的名称 |
get hint | undefined | Hint | 集合的当前索引提示 |
get namespace | string | 集合的命名空间,格式为${this.dbName}.${this.collectionName} 。 |
get readConcern | undefined | ReadConcern | 集合的当前readConcern 。如果没有为此集合明确定义,则将从父数据库继承 |
get readPreference | undefined | ReadPreference | 集合的当前readPreference 。如果没有为此集合明确定义,则将从父数据库继承 |
get writeConcern | undefined | WriteConcern | 集合的当前writeConcern 。如果没有为此集合明确定义,则将从父数据库继承 |
方法
方法 | 返回类型 | 说明 |
---|---|---|
aggregate(pipeline?, options?) | AggregationCursor | 针对集合执行聚合框架管道。可选的options参数是AggregateOptions的实例 |
bulkWrite(operations, options?) | Promise<BulkWriteResult> | 在没有fluent API的情况下执行bulkWrite操作。options可以是insertOne|replaceOne|updateOne|updateMany|deleteOne|deleteMany |
count(filter?, options?) | Promise<number> | 数据库中与筛选器匹配的文档的估计计数。可选的options参数是CountOptions的实例。 |
countDocuments(filters?, options?) | Promise<number> | 获取与筛选器匹配的文档数。可选的options参数是CountDocumentsOptions的实例。 |
createIndex(indexSpec, options) | Promise<string> | 在数据库和集合上创建索引。indexSpec是indexDescription对象。可选的options参数是CreateIndexesOptions的实例。 |
createIndexes(indexSpecs, options) | Promise<string[]> | 在集合上创建多个索引。indexSpecs是indexDescription对象的数组。可选的options参数是CreateIndexesOptions的实例。 |
createSearchIndex(description) | Promise<string> | 为集合创建单个搜索索引。string是索引的名称。description是SearchIndexDescription对象。仅在针对7.0以上Atlas群集使用时可用。 |
createSearchIndexes(descriptions) | Promise<string[]> | 为当前集合创建多个搜索索引。descriptions是SearchIndexDescription对象的数组。仅在针对7.0以上Atlas群集使用时可用。 |
deleteMany(filter?, options?) | Promise<DeleteResult> | 从集合中删除多个文档。可选的options参数是DeleteOptions的实例。 |
deleteOne(filter?, options?) | Promise<DeleteResult> | 从集合中删除一个文档。可选的options参数是DeleteOptions的实例。 |
distinct(key, filter?, options?) | Promise<Flatten<WithId<TSchema>[Key]>[]> | 返回集合中给定键的不同值列表。key可以是string、number或symbol。可选的options参数是CommandOperationOptions的实例。 |
drop(options?) | Promise<boolean> | 从数据库中删除集合,并将其永久删除。新的访问将创建一个新的集合。 |
dropIndex(indexName, options?) | Promise<Document> | 从此集合中删除索引。可的options参数是CommandOperationOptions的实例。 |
dropIndexes(options?) | Promise<boolean> | 从此集合中删除所在的索引(_id 索引除外) |
dropSearchIndex(name) | Promise<void> | 按索引名称删除搜索索引。仅在针对7.0以上Atlas群集使用时可用。 |
estimatedDocumentCount(options?) | Promise<number> | 使用集合元数据获取集合中文档数的估计值。可选的options参数是EstimatedDocumentCountOptions的实例 |
find(filter, options?) | FindCursor<WithId<Tchema>> | 为筛选器创建一个游标,该筛选器可用于迭代MongoDB的结果。可选的options参数是FindOptions的实例 |
findOne(filter, options?) | Promise<null|WithId<TSChema>> | 获取与筛选器匹配的第一个文档。可选的options参数是findOptions的实例 |
findOneAndDelete(filter, options?) | Promise<ModifyResult<TSchema>>(如果options参数的 includeResultMetadata为true) Promise<null|WithId<TSchema>>(如果options参数的includeResultMetadata为false) | 在一个原子操作中查找文档并将其删除。在操作期间需要写锁定。可选的options参数是FindOneAndDeleteOptions的实例。 |
findOneAndReplace(filter,replacement, options?) | Promise<ModifyResult<TSchema>>(如果options参数的includeResultMetadata为true) Promise<null|WithId<TSchema>>(如果options参数的includeResultMetadata为false) | 查找文档并在一个原子操作中替换它。在操作期间需要写锁定。可选的options参数是FindOneAndReplaceOptions的实例。 |
findOneAndUpdate(filter,update,options?) | Promise<ModifyResult<TSchema>>(如果options参数的includeResultMetadata为true) Promise<null|WithId<TSchema>>(如果options参数的includeResultMetadata为false) | 查找文档并在一个原子操作中更新它。在操作期间需要写锁定。可选的options参数是FindOneAndUpdateOptions的实例。 |
indexExists(indexes, options?) | Promise<boolean> | 检查集合中是否存在一个或多个索引,在第一个不存在的索引上失败。可选的options参数是indexInformationOptions的实例。 |
indexInformation(options?) | Promise<Document> | 检索此集合的索引信息。可选的options参数是indexInformationOptions的实例。 |
indexes | Promise<Document[]> | 检索集合上的所有索引。 |
initializeOrderedBulkOp(options?) | OrderedBulkOperation | 启动按顺序大容量写入操作。操作将按添加顺序串行执行,为类型中的每个开关创建一个新操作。可选的options参数是BulkWriteOptions的实例。 |
initializeUnorderedBulkOp(options?) | UnorderBulkOpration | 启动无序批量写入操作。所有操作都将被缓冲到无序执行的insert/update/remove命令中。可选的options参数是BulkWriteOptions的实例。 |
insertMany(docs, options?) | Promise<InsertManyResult<TSchema>> | 在MongoDB中插入一组文档。如果传入的文档不包含_id字段,则驱动程序将向缺少该字段的每个文档添加该字段,从而使文档发生变化。可选的options参数是BulkWriteOptions的实例。 |
insertOne(doc, options?) | Promise<InsertOneResult<TSchema>> | 在MongoDB中插入一个文档。如果传入的文档不包含_id字段,则驱动程序将向缺少该字段的每个文档添加该字段。可选的options参数是InsertOneOptions的实例。 |
isCapped(options?) | Promise<boolean> | 如果集合是封顶集合,则返回true 。可选的options参数是OperationOptions的实例。 |
listIndexes(options?) | ListIndexesCursor | 获取集合的所有索引信息的列表。可选的options参数是ListIndexesOptions的实例。 |
listSearchIndexes(name, options?) | ListSearchIndexesCursor | 返回当前集合的所有搜索索引。仅在针对7.0以上Atlas群集使用时可用。可选的options参数是AggregateOptions的实例。 |
rename(newName, options?) | Promise<Collection<Document>> | 重命名集合。可选的options参数是RenameOptions的实例。 |
replaceOne(filter, replacement, options?) | Promise<Document|UpdateResult<Tschema>> | 用另一个文档替换集合中的文档。可选的options参数是ReplaceOptions的实例。 |
updateMany(filter, update, options?) | Promise<UpdateResult<TSchema>> | 更新集合中的多个文档。可选的options参数是UpdateOptions的实例。 |
updateOne(filter, update, options?) | Promise<UpdateResult<TSchema>> | 更新集合中的单个文档。可选的options参数是UpdateOptions的实例。 |
updateSearchIndex(name, definition) | Promise<void> | 通过用提供的定义替换现有索引定义来更新搜索索引。仅在针对7.0以上Atlas群集使用时可用。 |
watch(pipeline?, options?) | ChangeStream | 创建一个新的更改流,监视此集合中的新更改(插入、更新、替换、删除和无效)。可选的options参数是ChangeStreamOptions的实例。 |
ChangeStream类
构造函数
没有构造函数。使用Collection.watch(pipeline?, options?)
创建。创建一个新的变更流实例。
options的内容(ChangeStreamOptions类的实例)
子项 | 类型 | 说明 |
---|---|---|
allowDiskUse | boolean | 是否可以使用磁盘存储聚合的临时结果 |
authdb | string | |
batchSize | number | 每批要返回的文档数 |
bsonRegExp | boolean | 将BSON正则表达式作为BSONRegExp实例返回。 |
bypassDocumentValidation | boolean | 允许驱动程序绕过架构验证 |
checkKeys | boolean | 序列化程序将检查键是否有效 |
collation | CollationOptions | 指定排序规则 |
comment | 任何有效的BSON类型 | 要应用于操作的注释。 |
cursor | document | 将查询作为游标返回 |
dbName | string | 数据库名称 |
enableUtf8Validation | boolean | 在反序列化BSON文档时启用utf8验证。默认为true |
explain | ExplainVerbosityLike | 指定解释输出的详细模式 |
fieldsAsRaw | Document | 允许指定我们希望返回哪些字段作为未序列化的原始缓冲区 |
fullDocument | string | 允许的值:“updateLookup”、“whenAvailable”、“required”。 |
fullDocumentBeforeChange | string | 允许的值:“whenAvailable”、“required”、“off”。 |
hint | document | 向聚合命令添加索引选择提示 |
ignoreUndefined | boolean | 序列化不会发出未定义的字段。默认值为true |
let | document | 可以使用$$var 访问的参数名称和值的映射(需要MongoDB 5.0) |
maxAwaitTimeMS | number | 服务器等待新文档以满足更改流查询的最长时间 |
maxTimeMS | number | 指定处理游标上的操作的累积时间限制(以毫秒为单位)。 |
noResponse | boolean | |
omitReadPreference | string | 当反序列化Binary时,它将作为nodejs Buffer实例返回。 |
out | string | |
promoteBuffers | string | |
promoteLongs | boolean | 当反序列化Long时,如果它小于53位,则将其放入Number中 |
promoteValues | boolean | 反序列化时将BSON值提升为其Node.js最接近的等效类型 |
raw | boolean | 启用raw选项将返回使用allocUnsafe API分配的Node.js缓冲区。 |
readConcern | ReadConcernLike | 指定集合的读取关注和级别 |
readPreference | ReadPreferenceLike | 首选读取首选项 |
resumeAfter | unknown | 允许您在指定事件之后启动changeStream |
retryWrites | boolean | 应重试失败的写入 |
serializeFunctions | bolean | 序列化javascript函数 |
session | ClientSession | 为此命令指定ClientSession |
showExplandedEvents | boolean | 启用时,将更改流配置为包括额外的更改事件 |
startAfter | unknown | 类似于resumeAfter ,但允许您在无效事件后启动 |
startAtOperationTime | Timestamp | 将在指定的operationTime之后启动changeStream |
useBigInt64 | boolean | 当反序列化一个Long时,指示是否可以以BigInt的形式返回 |
willRetryWrite | boolean | 是否将重试写入 |
属性
属性 | 类型 | 说明 |
---|---|---|
namespace | MongoDBNamespace | |
options | ChangeStreamOPtions & {writeConcern?: undefined;} | |
pipeline | Document[] | |
streamOptions | CursorStreamOptions | |
type | symbol | |
static readonly CHANGE | "change" | 为指定命名空间中的每个新匹配更改激发。 |
static readonly CLOSE | "close" | |
static readonly END | "end" | |
static readonly ERROR | "error" | |
static readonly INIT | "init" | |
static readonly MORE | "more" | |
static readonly RESPONSE | "response" | |
static readonly RESUME_TOKEN_CHANGED | "resumeTokenChanged" | |
static readonly captureRejectionSymbol | captureRejectionSymbol | |
static captureRejections | boolean | 设置或获取所有发射器的默认captureRejection值。 |
static defaultMaxListeners | number | errorMonitor |
static readonly errorMonitor |
访问器
访问器 | 返回类型 | 说明 |
---|---|---|
get closed | boolean | 游标是否关闭 |
get resumeToken | unknown | 缓存的恢复令牌,用于在最近返回的更改之后恢复 |
方法
方法 | 返回类型 | 说明 |
---|---|---|
[asyncIterator]() | AsyncGenerator<TChange, void, void> | |
addListener(event, listener) | ChangeStream | |
close() | Promise<void> | |
emit(event, ...args) | ||
eventNames() | string[] | |
getMaxListeners() | number | |
hasNext() | Promise<bollean> | 检查变更流中是否还有可用的文档 |
listenerCount(eventName) | number | eventName的值为 "error"、"close"、"response"、"more"、"init"、"change"、"end"、"resumeTokenChanged" |
listeners(eventName) | ChangeStreamEvents | eventName的值为 "error"、"close"、"response"、"more"、"init"、"change"、"end"、"resumeTokenChanged" |
next() | Promise<TChange> | 从变更流中获取下一个可用文档 |
off(eventName, listener) | ChangeStream | eventName的值为 "error"、"close"、"response"、"more"、"init"、"change"、"end"、"resumeTokenChanged" |
on(eventName, listener) | ChangeStream | eventName的值为 "error"、"close"、"response"、"more"、"init"、"change"、"end"、"resumeTokenChanged" |
once(eventName, listener) | ChangeStream | eventName的值为 "error"、"close"、"response"、"more"、"init"、"change"、"end"、"resumeTokenChanged" |
prependListener(eventName, listener) | ChangeStream | eventName的值为 "error"、"close"、"response"、"more"、"init"、"change"、"end"、"resumeTokenChanged" |
prependOnceListener(eventName, listener) | ChangeStream | |
rawListeners(eventName) | ChangeStreamEvents | |
removeAllListeners(eventName?) | ChangeStream | |
removeListener(eventName, listener) | ChangeStream | |
setMaxListeners(n) | ChangeStream | |
stream(options?) | Readable & AsyncIterable | 返回一个修改后的Readable流,其中包括一个可能的转换方法 |
tryNext() | Promise<null|TChange> | 尝试从更改流的游标获取下一个可用文档,如果返回空批,则为null |
static getEventListeners(n?,...eventTargets) | void | 每个EventTarget事件的最大侦听器数 |
Admin类
构造函数
没有构造函数,使用db.admin()
来实例化。该方法没有参数。
方法
方法 | 返回类型 | 说明 |
---|---|---|
buildInfo(options?) | Promise<Document> | 检索服务器内部版本信息。可选的options参数是CommandOperationOptions的实例 |
command(command, options?) | Promise<Document> | 执行命令。可选的options参数是RunCommandOptions的实例。 |
listDatabases(options?) | Promise<ListDatabaseResult> | 列出可用的数据库。可选的options参数是ListDatabaseOptions的实例。 |
ping(options?) | Promise<Document> | Ping MongoDB服务器并检索结果。可选的options参数是CommandOperationOptions的实例。 |
removeUser(username, options?) | Promise<boolean> | 从数据库中删除用户。可选的options参数是CommandOperationOptions的实例。 |
replSetGetStatus(options?) | Promise<Document> | 获取副本集的状态。可选的options参数是CommandOperationOptions的实例。 |
serverInfo(options?) | Promise<Document> | 检索服务器内部版本信息。可选的options参数是CommandOperationOptions的实例。 |
serverStatus(options?) | Promise<Document> | 检索此数据库的服务器状态。可选的options参数是CommandOperationOptions的实例。 |
validateCollection(collectionName, options?) | Promise<Document> | 验证现有集合。可选的options参数是ValidateCollections的实例。 |
ServerSession类
构造函数
没有构造函数,可以使用ClientSession.serverSession()
来实例化。
写入选项
FindOneAndDeleteOptions | FindOneAndReplaceOptions | FindOneAndUpdateOptions | FindOptions | DeleteOptions | InsertOneOptions | UpdateOptions | BulkWriteOptions | ReplaceOptions |
authdb:string bsonRegExp:boolean checkKeys:boolean collation:CollationOptions comment:unknown dbName:string enableUtf8Validation:boolean explain:ExplainVerbosityLike fieldsAsRaw:Document hint:Document ignoreUnderfined:boolean includeResultMetadata:boolean let:Document maxTimeMS:number noResponse:boolean omitReadReference:boolean projection:Document promoteBuffers:boolean promoteLong:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean serializeFunctions:boolean session:ClientSession> sort:Sort useBigInt64:boolean willRetryWrite:boolean writeConcern:writeConcern | authdb:string bsonRegExp:boolean bypassDocumentValidation:boolean checkKeys:boolean collation:CollationOptions comment:unknown dbName:string enableUtf8Validation:boolean explain:ExplainVerbosityLike fieldsAsRaw:Document hint:Document ignoreUndefined:boolean includeResultMetadata:boolean let:Document maxTimeMS:number noResponse:boolean omitReadPreference:boolean projection:Document promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean returnDocument:ReturnDocument serializeFunctions:boolean session:ClientSession sort:Sort upsert:boolean useBigInt64:boolean willRetryWrite:boolean writeConcern:WriteConcern |
arrayFilters:Document[] authdb:string bsonRegExp:boolean bypassDocumentValidation:boolean checkKeys:boolean collation:CollationOptions comment:unknown dbName:string enableUtf8Validation explain:ExplainVerbosityLike fieldsAsRaw:Document hint:Document ignoreUndefined:boolean includeResultMetadata:boolean let:Document maxTimeMS:number noResponse:boolean omitReadPreference:boolean projection:Document promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean returnDocument:ReturnDocument serializeFunctions:boolean session:ClientSession sort:Sort upsert:boolean usebigInt64:boolean willRetryWrite:boolean writeConcern:WriteConcern |
allowDiskUse:boolean allowPartialResults:boolean authdb:string awaitData:boolean batchSize:number bsonRegExp:boolean checkKeys:boolean collation:CollactionOptions comment:unknown dbName:string enableUtf8Validation:boolean explain:ExplainVerbosityLike fieldsAsRaw:Document hint:Hint ignoreUndefined:boolean let:Document limit:number max:Document maxAwaitTimeMS:number maxTimeMS:number min:Document noCursorTimeout:boolean noResponse:boolean omitReadPreference:boolean projection:Document promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean returnKey:boolean serializeFunctions:boolean session:ClientSession showRecordId:boolean singleBatch:boolean skip:number sort:Sort tailable:boolean timeout:boolean useBigInt64:boolean willRetryWrite:boolean | authdb:string bsonRegExp:boolean checkKeys:boolean collation:CollationOptions comment:unknown dbName:string enableUtf8Validation:boolean explain:ExplainVerbosityLike fieldsAsRaw:Document hint:Doucment ignoreUndefined let:Document maxTimeMS:number noREsponse:boolean omitReadPreference:boolean ordered:boolean promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean serializeFunctions:boolean session:ClientSession useBigInt64:boolean willRetryWrite:boolean writeConcern:writeConcern |
authdb:string bsonRegExp:boolean bypassDocumentValidation:boolean checkKeys:boolean collation:CollationOptions comment:unknown dbName:string enableUtf8Validation explain:ExplainVerbosityLike fieldsAsRaw:Document forceServerObjectId:boolean ignoreUndefined:boolean maxTimeMs:number noReponse:boolean omitReadPreference:boolean promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean serializeFunctions:boolean session:ClientSession useBigInt64:boolean willRetryWrite:boolean writeConcern:WriteConcern |
arrayFilters:Document[] authdb:string bsonRegExp:boolean bypassDocumentValidation checkKeys:boolean collation:CollationOptions comment:unknown dbName:string enableUtf8Validation explain:ExplainVerbosityLike fieldsAsRaw:Document hint:Hint ignoreUndefined:boolean let:Document maxTimeMS:number noReponse:boolean omitReadPreference:boolean promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean serializeFunction:boolean session:ClientSession upsert:boolean useBigInt64:boolean willRetryWrite:boolean writeConcern:writeConcern |
authdb:string bsonRegExp:boolean bypassDocumentValidation:boolean checkKeys:boolean collation:CollationOptions comment:unknown dbName:string enableUtf8Validation:boolean explain:ExplainVerbosityLike fieldAsRaw:Document forceServerObjectId:boolean ignoreUndefined:boolean let:Document maxTimeMS:number noResponse:boolean omitReadPreference:boolean ordered:boolean promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean serializeFunctions:boolean session:ClientSession useBigInt64:boolean willRetryWrite:boolean writeConcern:writeConcern |
authdb:string bsonRegExp:boolean bypassDocumentValidation:boolean checkKeys:boolean collation:CollactionOptions comment:unknown dbName:string enableUtf8Validation:boolean explain:ExplainVerbosityLike fieldsAsRaw:Document hint:Document ignoreUndefined:boolean let:Document maxTimeMs:number noResponse:boolean omitREadPreference:boolean promoteBuffers:boolean promoteLongs:boolean promoteValues:boolean raw:boolean readConcern:ReadConcernLike readPreference:ReadPreferenceLike retryWrites:boolean serializeFunctions:boolean session:ClientSession upsert:boolean useBigInt64:boolean willRetryWrite:boolean |
游标
AggregationCursor | FindCursor | ListCollectionsCursor | ListIndexesCursor | |
访问器 | get closed:boolean get id:undefined get killed:boolean get loadBalanced:boolean get namespace:MongoDBNameSpace get pipeline:Document[] get readConcern:undefined get readPreference:ReadPreference set session(clientSession):void | get closed:boolean get id:undefined get killed:boolean get loadBalanced:boolean get namespace:boolean get readConcern:undefined|ReadConcern get readPreference:ReadPreference set session(clientSession):void | get closed:boolean get id:undefined get killed:boolean get loadBalanced:boolean get namespace:MongoDBNamespace get readConcern:undefined|ReadConcern get readPreference:ReadPreference set session(clientSession):void | get closed:boolean get id:undefined|long get killed:boolean get loadBalanced:boolean get namespace:MongoDBNamespace get readConcern:undefined|ReadConcern get readPreference:ReadPreference set session(clientSession):void |
方法 | addCursorFlag(flag, value): AggregationCursor<TSchema> addListener(eventName, listener): AggregationCursor<TSchema> batchSize(value):AggregationCursor<TSchema> bufferedCount():number clone():AggregationCursor<TSchema> close():Promise<void> emit(eventName,...args):boolean eventNames():string[] explain(verbosity?):Promise<Document> forEach(iterator):Promise<void> geoNear($geoNear):AggregationCursor<TSchema> getMaxListeners():number group($group):AggregationCursor<TSchema> hasNext():Promise<boolean> limit($limit):AggregationCursor<TSchema> listenerCount(type):number listeners(eventName):AbstractCursorEvents[EventKey][] lookup($lookup):AggregationCursor<TSchema> map(transform):AggregationCursor<TSchema> match($match):AggregationCursor<TSchema> maxTimeMS(value):AggregationCursor<TSchema> next():Promise<null|TSchema> off(eventName, listener):AggregationCursor<TSchema> on(eventName, listener):AggregationCursor<TSchema> once(eventName, listener):AggregationCursor<TSchema> out($out):AggregationCursor<TSchema> prependListener(eventName, listener):AggregationCursor<TSchema> prependOnceListener(eventName, listener)::AggregationCursor<TSchema> project($project):AggregationCursor<TSchema> rawListeners(eventName):AbstractCursorEvents[EventKey][] readBufferedDocuments(number?):TSchema[] redact($redact):AggregationCursor<TSchema> removeAllListeners(eventName?):AggregationCursor<TSchema> removeListener(event, listener):AggregationCursor<TSchema> rewind():void setMaxListeners(n):AggregationCursor<TSchema> skip($skip):AggregationCursor<TSchema> sort($sort):AggregationCursor<TSchema> stream(options?): Readable & AsyncIterable<TSchema> toArray():Promise<TSchema[]> tryNext():Promise<null|TSchema> unwind($unwind):AggregationCursor<TSchema> withReadConcern(readConcern):AggregationCursor<TSchema> withReadPreference(readPreference):AggregationCursor<TSchema> |
addCursorFlag(flag,value):FindCursor<TSchema> addListener(eventName, listener):FindCursor<TSchema> addQueryModifier(name, value):FindCursor<TSchema> allowDiskUse(allow?):FindCursor<TSchema> batchSize(value):FindCursor<TSchema> bufferedCount():number clone():FindCursor<TSchema> close():Promise<void> collation(value):FindCursor<TSchema> comment(value):FindCursor<TSchema> count(options?):Promise<number> emit(eventName, ...args):boolean eventNames():string[] explain(verbosity?):Promise<Document> filter(filter):FindCursor<TSchema> forEach(iterator):Promise<void> getMaxListeners():number hasNext():Promise<boolean> hint(hint):FindCursor<TSchema> limit(value):FindCursor<TSchema> listenerCount(type):number listeners(eventName):AbstractCursorEvents[EventKey][] map(transform):FindCursor<TSchema> max(max):FindCursor<TSchema> maxAwaitTimeMS(value):FindCursor<TSchema> maxTimeMS(value):FindCursor<TSchema> min(min):FindCursor<TSchema> next():Promise<null|TSchema> off(eventName, listener):FindCursor<TSchema> on(eventName, listener):FindCursor<TSchema> once(eventName, listener):FindCursor<TSchema> prependListener(eventName, listener):FindCursor<TSchema> prependOnceListener(eventName, listener):FindCursor<TSchema> project(value):FindCursor<T> rawListeners(event):AbstractCursorEvents[EventKey][] readBufferedDocuments(number?):TSchema[] removeAllListeners(eventName?):FindCursor<TSchema> removeListener(eventName, listener):FindCursor<TSchema> returnKey(value):FindCursor<TSchema> rewind():void setMaxListeners(n):FindCursor<TSchema> showRecordId(value):FindCursor<TSchema> sort(sort, direction?):FindCursor<TSchema> stream(options?):Readable&AsyncIterable<TSchema> toArray():Promise<TSchema[]> tryNext():Promise<null|TSchema> withReadConcern(readConcern):FindCursor<TSchema> withReadPreference(readPreference):FindCursor<TSchema> | addCursorFlag(flag, value):ListCollectionsCursor<T> addListener(eventName, listener):ListCollectionsCursor<T> batchSize(value):ListCollectionsCursor<T> bufferedCount():number clone():ListCollectionsCursor<T> close():Promise<void> emit(eventName,...args):boolean eventNames():string[] forEach(iterator):Promise<void> getMaxListeners():number hasNext():Promise<boolean> listenerCount(type):number listeners(event):AbstractCursorEvents[EventKey][] map(transform):AbstractCursor<T,AbstractCursorEvents> maxTimeMS(value):ListCollectionsCursor<T> next():Promise<null|T> off(eventName, listener):ListCollectionsCursor<T> on(eventName, listener):ListCollectionsCursor<T> once(eventName, listener):ListCollectionsCursor<T> prependListener(eventName, listener):ListCollectionsCursor<T> prependOnceListener(eventName, listener):ListCollectionsCursor<T> rawListeners(eventName):AbstractCursorEvents[EventKey][] readBufferedDocuments(number?):T[] removeAllListeners(eventName?):ListCollectionsCursor<T> removeListener(eventName, listener):ListCollectionsCursor<T> rewind():void setMaxListeners(n):ListCollectionCursor<T> toArray():Promise<T[]> tryNext():Promise<null|T> withReadConcern(readConcern):ListCollectionsCursor<T> withReadPreference(readPreference):ListCollectionsCursor<T> | addCursorFlag(flag, value):ListIndexesCursor addListener(eventName, listener):ListIndexesCursor batchSize(value):ListIndexesCursor bufferedCount():number clone():ListIndexesCursor close():Promise<void> emit(eventName, ...args):boolean eventNames():string[] forEach(iterator):Promise<void> getMaxListeners():number haxNext():Promise<boolean> listenerCount(type):number listeners(eventName):AbstractCursorEvents[EventKey][] map(transform):AbstractCursor<T, AbstractCursorEvents> maxTimeMS(value):ListIndexesCursor next():Promise<any> off(eventName, listener):ListIndexesCursor on(eventName, listener):ListIndexesCursor once(eventName, listener):ListIndexesCursor prependListener(eventName, listener):ListIndexesCursor prependOnceListener(eventName, listener):ListIndexesCursor rawListeners(eventName):AbstractCursorEvents[EventKey][] readBufferedDocuments(number?):any[] removeAllListeners(eventName?):ListIndexesCursor removeListener(eventName, listener):ListIndexesCursor rewiind():void setMaxListeners(n):ListIndexesCursor stream(options?)Readable&AsyncIterable<any> toArray():Promise<any[]> tryNext():Promise<any> withReadConcern(readConcern):ListIndexesCursor withReadPreference(readPreference):ListIndexesCursor |
输出结果
BulkWriteResult | DeleteResult | ModifyResult | InsertManyResult | InsertOneResult | UpdateResult | |
属性 | deleteCount:number insertedCount:number isertedIds:{[key:number]:any;} matchedCount:number modifiedCount:number upsertedCount:number; upsertedIds:{[key:number]:any} | acknowledged:boolean deletedCount:number | lastErrorObject:Document ok:0|1 value:null|WithId<TSchema> | acknowledged:boolean insertedCount:number insertedIds:{[key:number]:InferIdType:<TSchema>} | acknowledged:boolean insertedId:InferIdType<TSchema> | acknowledged:boolean matchedCount:number modifiedCount:number upsertedCount:number upsertedId:null|InferIdType<TSchema> |
访问器 | get ok:number | |||||
方法 | getRawResponse:():Document getUpsertedIdAt(index):undefined getWriteConcernError():undefined|WriteConcernError getWriteErrorAt(index):undefined|WriteError getWriteErrorCount():number getWriteErrors():boolean isOK():boolean toString():string |