Note
JavaScript in MongoDBMongoDB中的JavaScript
Although these methods use JavaScript, most interactions with MongoDB do not use JavaScript but use an idiomatic driver in the language of the interacting application.虽然这些方法使用JavaScript,但与MongoDB的大多数交互都不使用JavaScript,而是使用交互应用程序语言中的惯用驱动程序。
Note
For details on a specific method, including syntax and examples, click on the link to the method's reference page.有关特定方法的详细信息,包括语法和示例,请单击该方法参考页面的链接。
MongoDB Search Index MethodsMongoDB搜索索引方法
MongoDB Search indexes let you query data in MongoDB Search, while Vector Search indexes let you query data in Vector Search. MongoDB搜索索引允许您在MongoDB搜索中查询数据,而矢量搜索索引则允许您在矢量搜索中查询。MongoDB Search and Vector Search indexes enable performant text search queries by mapping search terms to the documents that contain those terms.MongoDB搜索和矢量搜索索引通过将搜索词映射到包含这些词的文档,实现了高性能的文本搜索查询。
Use the following methods to manage MongoDB Search and Vector Search indexes.使用以下方法管理MongoDB搜索和矢量搜索索引。
db.collection.createSearchIndex() | |
db.collection.dropSearchIndex() | |
db.collection.getSearchIndexes() | |
db.collection.updateSearchIndex() |
Atlas Stream Processing MethodsAtlas流处理方法
Atlas Stream ProcessorsAtlas流处理器 let you perform aggregation operations against streams of continuous data using the same data model and query API that you use with at-rest data.允许您使用与静态数据相同的数据模型和查询API对连续数据流执行聚合操作。
Use the following methods to manage Stream Processors:使用以下方法管理流处理器:
Important
The following methods can only be run on deployments hosted on MongoDB Atlas.以下方法只能在MongoDB Atlas上托管的部署上运行。
sp.createStreamProcessor() | |
sp.listStreamProcessors() | |
sp.process() | |
sp.processor.drop() | |
sp.processor.sample() | |
sp.processor.start() | |
sp.processor.stats() | |
sp.processor.stop() |
Collection集合
db.collection.analyzeShardKey() | |
db.collection.aggregate() | |
db.collection.bulkWrite() | |
db.collection.compactStructuredEncryptionData() | compactStructuredEncryptionData to return a success or failure object.compactStructuredEncryptionData以返回成功或失败对象。 |
db.collection.configureQueryAnalyzer() | |
db.collection.count() | count to return a count of the number of documents in a collection or a view.count返回集合或视图中文档数量的计数。 |
db.collection.countDocuments() | $group aggregation stage with a $sum expression to return a count of the number of documents in a collection or a view.$sum表达式包装$group聚合阶段,以返回集合或视图中文档数量的计数。 |
db.collection.createIndex() | |
db.collection.createIndexes() | |
db.collection.dataSize() | size field in the output of the collStats.size字段包裹在collStats的输出中。 |
db.collection.deleteOne() | |
db.collection.deleteMany() | |
db.collection.distinct() | |
db.collection.drop() | |
db.collection.dropIndex() | |
db.collection.dropIndexes() | |
db.collection.estimatedDocumentCount() | count to return an approximate count of the documents in a collection or a view.count返回集合或视图中文档的近似计数。 |
db.collection.explain() | |
db.collection.find() | |
db.collection.findAndModify() | |
db.collection.findOne() | |
db.collection.findOneAndDelete() | |
db.collection.findOneAndReplace() | |
db.collection.findOneAndUpdate() | |
db.collection.getIndexes() | |
db.collection.getShardDistribution() | db.collection.getShardDistribution() reports data of chunk distribution.db.collection.getShardDistribution()报告块分布的数据。 |
db.collection.getShardVersion() | |
db.collection.hideIndex() | |
db.collection.insertOne() | |
db.collection.insertMany() | |
db.collection.isCapped() | |
db.collection.latencyStats() | |
db.collection.mapReduce() | |
db.collection.reIndex() | |
db.collection.remove() | |
db.collection.renameCollection() | |
db.collection.replaceOne() | |
db.collection.stats() | collStats.collStats提供包装。 |
db.collection.storageSize() | storageSize field of the collStats output.collStats输出的storageSize字段提供包装。 |
db.collection.totalIndexSize() | totalIndexSize field of the collStats output.collStats输出的totalIndexSize字段提供包装。 |
db.collection.totalSize() | |
db.collection.unhideIndex() | |
db.collection.updateOne() | |
db.collection.updateMany() | |
db.collection.watch() | |
db.collection.validate() |
Cursor游标
cursor.addOption() | |
cursor.allowDiskUse() | |
cursor.batchSize() | |
cursor.close() | |
cursor.isClosed() | true if the cursor is closed.true。 |
cursor.collation() | db.collection.find().db.collection.find()返回的游标的排序规则。 |
cursor.comment() | |
cursor.count() | |
cursor.explain() | |
cursor.forEach() | |
cursor.hasNext() | true。 |
cursor.hint() | |
cursor.isExhausted() | true if the cursor is closed and there are no objects remaining in the batch.true。 |
cursor.itcount() | |
cursor.limit() | |
cursor.map() | |
cursor.max() | cursor.hint()cursor.hint()一起使用 |
cursor.maxTimeMS() | |
cursor.min() | cursor.hint()cursor.hint()一起使用 |
cursor.next() | |
cursor.noCursorTimeout() | |
cursor.objsLeftInBatch() | |
cursor.pretty() | |
cursor.readConcern() | find() operation.find()操作的读取关注。 |
cursor.readPref() | |
cursor.returnKey() | |
cursor.showRecordId() | |
cursor.size() | skip() and limit() methods.skip()和limit()方法后,返回游标中文档的计数。 |
cursor.skip() | |
cursor.sort() | |
cursor.tailable() | |
cursor.toArray() |
Database数据库
db.adminCommand() | admin database.admin数据库运行命令。 |
db.aggregate() | |
db.commandHelp() | |
db.createCollection() | |
db.createView() | |
db.currentOp() | |
db.dropDatabase() | |
db.fsyncLock() | fsync.fsync。 |
db.fsyncUnlock() | db.fsyncLock().db.fsyncLock()锁定的数据库上继续写入。 |
db.getCollection() | mongosh. |
db.getCollectionInfos() | |
db.getCollectionNames() | |
db.getLogComponents() | |
db.getMongo() | Mongo() connection object for the current connection.Mongo()连接对象。 |
db.getName() | |
db.getProfilingStatus() | |
db.getReplicationInfo() | |
db.getSiblingDB() | |
db.hello() | |
db.help() | db object methods.db对象方法的描述。 |
db.hostInfo() | hostInfohostInfo |
db.killOp() | |
db.listCommands() | |
db.logout() | |
db.printCollectionStats() | db.collection.stats().db.collection.stats()。 |
db.printReplicationInfo() | |
db.printSecondaryReplicationInfo() | |
db.printShardingStatus() | |
db.rotateCertificates() | rotateCertificates.rotateCertificates(旋转证书)。 |
db.runCommand() | |
db.serverBuildInfo() | mongod instance. Wraps buildInfo.mongod实例的编译参数。包装buildInfo。 |
db.serverCmdLineOpts() | getCmdLineOpts.getCmdLineOpts。 |
db.serverStatus() | |
db.setLogLevel() | |
db.setProfilingLevel() | |
db.shutdownServer() | mongod or mongos process cleanly and safely.mongod或mongos进程。 |
db.stats() | |
db.version() | mongod instance.mongod实例的版本。 |
db.watch() | system collections. admin, local or config databases.admin、local或config数据库上打开。 |
Query Plan Cache查询计划缓存
db.collection.getPlanCache() | |
PlanCache.clear() | db.collection.getPlanCache().clear().db.collection.getPlanCache().clear()。 |
PlanCache.clearPlansByQuery() | db.collection.getPlanCache().clearPlansByQuery() |
PlanCache.help() | db.collection.getPlanCache().help().db.collection.getPlanCache().help()。 |
PlanCache.list() | db.collection.getPlanCache().list().db.collection.getPlanCache().list()。 |
Bulk Write Operation批量写入操作
db.collection.initializeOrderedBulkOp() | Bulk() operations builder for an ordered list of operations.Bulk()操作生成器。 |
db.collection.initializeUnorderedBulkOp() | Bulk() operations builder for an unordered list of operations.Bulk()操作生成器。 |
Mongo.bulkWrite() | |
Bulk() | |
Bulk.execute() | |
Bulk.find() | |
Bulk.find.arrayFilters() | update or updateOne operation.update或updateOne操作更新数组中哪些元素的筛选器。 |
Bulk.find.collation() | |
Bulk.find.delete() | |
Bulk.find.deleteOne() | |
Bulk.find.hint() | |
Bulk.find.remove() | Bulk.find.delete().Bulk.find.delete()的别名。 |
Bulk.find.removeOne() | Bulk.find.deleteOne().Bulk.find.deleteOne()的别名。 |
Bulk.find.replaceOne() | |
Bulk.find.updateOne() | |
Bulk.find.update() | multi update operation to a list of operations.multi更新操作添加到操作列表中。 |
Bulk.find.upsert() | upsert: true for an update operation.upsert: true。 |
Bulk.getOperations() | Bulk() operations object.Bulk()操作对象中执行的写入操作数组。 |
Bulk.insert() | |
Bulk.toJSON() | Bulk() operations object.Bulk()操作对象中的操作数和批处理数。 |
Bulk.toString() | Bulk.toJSON() results as a string.Bulk.toJSON()结果。 |
User Management用户管理
db.auth() | |
db.changeUserPassword() | |
db.createUser() | |
db.dropUser() | |
db.dropAllUsers() | |
db.getUser() | |
db.getUsers() | |
db.grantRolesToUser() | |
db.removeUser() | |
db.revokeRolesFromUser() | |
db.updateUser() | |
passwordPrompt() | mongosh user authentication/management methods.mongosh用户身份验证/管理方法中直接指定密码的替代方法。 |
Role Management角色管理
db.createRole() | |
db.dropRole() | |
db.dropAllRoles() | |
db.getRole() | |
db.getRoles() | |
db.grantPrivilegesToRole() | |
db.revokePrivilegesFromRole() | |
db.grantRolesToRole() | |
db.revokeRolesFromRole() | |
db.updateRole() |
Replication复制
rs.add() | |
rs.addArb() | |
rs.conf() | |
rs.freeze() | |
rs.help() | |
rs.initiate() | |
rs.printReplicationInfo() | |
rs.printSecondaryReplicationInfo() | |
rs.reconfig() | |
rs.remove() | |
rs.status() | |
rs.stepDown() | |
rs.syncFrom() |
Sharding分片
convertShardKeyToHashed() | |
db.checkMetadataConsistency() |
|
db.collection.checkMetadataConsistency() |
|
sh.abortMoveCollection() |
|
sh.abortReshardCollection() |
|
sh.addShard() | |
sh.addShardTag() | sh.addShardToZone().sh.addShardToZone()的别名。 |
sh.addShardToZone() | |
sh.addTagRange() | sh.updateZoneKeyRange().sh.updateZoneKeyRange()。 |
sh.balancerCollectionStatus() | |
sh.checkMetadataConsistency() |
|
sh.commitReshardCollection() |
|
sh.disableAutoMerger() |
|
sh.disableAutoSplit() |
|
sh.disableBalancing() | |
sh.enableAutoMerger() |
|
sh.enableAutoSplit() |
|
sh.enableBalancing() | sh.disableBalancing().sh.disableBalancing()禁用了分片集合平衡器进程,则激活该进程。 |
sh.enableSharding() | |
sh.getBalancerState() | |
sh.getShardedDataDistribution() | sh.getShardedDataDistribution() is a shell helper method for the $shardedDataDistribution aggregation pipeline stage.sh.getShardedDataDistribution()是$shardedDataDistribution聚合管道阶段的shell辅助方法。 |
sh.help() | sh methods.sh方法的帮助文本。 |
sh.isBalancerRunning() | |
sh.isConfigShardEnabled() | sh.isConfigShardEnabled() also returns host and tag information.sh.isConfigShardEnabled()也会返回主机和标签信息。 |
sh.listShards() | |
sh.moveChunk() | |
sh.moveCollection() | |
sh.moveRange() | |
sh.removeRangeFromZone() | |
sh.removeShardTag() | sh.removeShardFromZone().sh.removeShardFromZone()。 |
sh.removeShardFromZone() | |
sh.removeTagRange() | sh.removeRangeFromZone().sh.removeRangeFromZone()。 |
sh.reshardCollection() |
|
sh.setBalancerState() | |
sh.shardAndDistributeCollection() |
|
sh.shardCollection() | |
sh.splitAt() | |
sh.splitFind() | |
sh.startAutoMerger() |
|
sh.startBalancer() | |
sh.status() | db.printShardingStatus().db.printShardingStatus()。 |
sh.stopAutoMerger() |
|
sh.stopBalancer() | |
sh.unshardCollection() |
|
sh.updateZoneKeyRange() | |
sh.waitForBalancer() | |
sh.waitForBalancerOff() | |
sh.waitForPingChange() | mongos in the sharded cluster.mongos的ping状态发生变化。 |
Constructors构造函数
Binary.createFromBase64() | |
Binary.createFromHexString() | |
BinData() | |
BulkWriteResult() | Bulk.execute().Bulk.execute()的结果集进行包装。 |
Date() | |
HexData() | |
ObjectId() | |
ObjectId.createFromBase64() | |
ObjectId.createFromHexString() | |
ObjectId.getTimestamp() | |
ObjectId.toString() | |
UUID() (mongosh method) | |
WriteResult() |
Connection连接
connect() (mongosh method) | |
Mongo() | |
Mongo.getDB() | |
Mongo.getReadPrefMode() | |
Mongo.getReadPrefTagSet() | |
Mongo.setCausalConsistency() | |
Mongo.setReadPref() | |
Mongo.startSession() | |
Mongo.watch() | system collections across all its databases, excluding the internal admin, local, and config databases.admin、local和config数据库。 |
Session() | |
SessionOptions() |
In-Use Encryption使用中的加密
MongoDB supports two approaches to In-Use Encryption, Client-Side Field Level Encryption (CSFLE) and Queryable Encryption (QE). MongoDB支持两种使用中加密方法,客户端字段级加密(CSFLE)和可查询加密(QE)。ClientEncryption is an abstraction used across drivers and 是跨驱动程序和mongosh that encapsulates operations for both CSFLE and QE. mongosh使用的抽象,它封装了CSFLE和QE的操作。However, some methods are specific to one feature.然而,有些方法是特定于一个特征的。
Note
The mongosh ClientEncryption methods require a database connection with in-use encryption enabled. If the current database connection was not initiated with in-use encryption enabled, either:mongosh ClientEncryption方法需要启用正在使用的加密的数据库连接。如果当前数据库连接不是在启用使用中的加密的情况下启动的,则:
Use the使用Mongo()constructor from themongoshto establish a connection with the required in-use encryption options.mongosh中的Mongo()构造函数与所需的正在使用的加密选项建立连接。TheMongo()method supports the following Key Management Service (KMS) providers for Customer Master Key (CMK) management:Mongo()方法支持以下用于客户主键(CMK)管理的键管理服务(KMS)提供程序:Amazon Web Services KMS亚马逊网络服务KMSAzure Key VaultAzure键库Google Cloud Platform KMS谷歌云平台KMSLocally Managed Key本地管理键
or或者Use the使用mongoshcommand line options to establish a connection with the required options.mongosh命令行选项建立与所需选项的连接。The command line options only support the Amazon Web Services KMS provider for CMK management.命令行选项仅支持用于CMK管理的Amazon Web Services KMS提供程序。
Commands with aliases are grouped together.带有别名的命令被组合在一起。
| CSFLE | QE | ||
|---|---|---|---|
getKeyVault() | ✓ | ✓ | |
KeyVault.createKey()KeyVault.createDataKey() | ✓ | ✓ | |
KeyVault.deleteKey() | ✓ | ✓ | |
KeyVault.getKey() | ✓ | ✓ | |
KeyVault.getKeys() | ✓ | ✓ | |
KeyVault.addKeyAlternateName()KeyVault.addKeyAltName() | ✓ | ✓ | |
KeyVault.removeKeyAlternateName()KeyVault.removeKeyAltName() | ✓ | ✓ | |
KeyVault.getKeyByAltName() | ✓ | ✓ | |
KeyVault.rewrapManyDataKey() | ✓ | ✓ | |
getClientEncryption() | ✓ | ✓ | |
ClientEncryption.createEncryptedCollection() | ✓ | ✓ | |
ClientEncryption.encrypt() | ✓ | ✓ | |
ClientEncryption.encryptExpression() | ✓ | ||
ClientEncryption.decrypt() | ✓ | ✓ |