mongosh
Methods方法
On this page本页内容
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,而是使用交互应用程序语言中的惯用驱动程序。
For details on a specific method, including syntax and examples, click on the link to the method's reference page.有关特定方法的详细信息,包括语法和示例,请单击该方法参考页的链接。
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 .collStats 输出中的size 字段。 |
db.collection.deleteOne() | |
db.collection.deleteMany() | |
db.collection.distinct() | |
db.collection.drop() | |
db.collection.dropIndex() | |
db.collection.dropIndexes() | |
db.collection.ensureIndex() | db.collection.createIndex() .db.collection.createIndex() 。 |
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.allowPartialResults() | db.collection.find() operations against a sharded collection to return partial results, rather than an error, if one or more queried shards are unavailable.db.collection.find() 操作以返回部分结果,而不是错误。 |
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 .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.hostInfo() | hostInfo hostInfo |
db.killOp() | |
db.listCommands() | |
db.logout() | |
db.printCollectionStats() | db.collection.stats() .db.collection.stats() 。 |
db.printReplicationInfo() | |
db.printSecondaryReplicationInfo() | |
db.printShardingStatus() | |
db.printSlaveReplicationInfo() | db.printSecondaryReplicationInfo() instead. db.printSecondaryReplicationInfo() 。 |
db.resetError() | |
db.rotateCertificates() | rotateCertificates .rotateCertificates 。 |
db.runCommand() | |
db.serverBuildInfo() | mongod instance. mongod 实例的编译参数。buildInfo .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. system 集合。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() 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() 操作生成器。 |
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.printSlaveReplicationInfo() | rs.printSecondaryReplicationInfo() instead. rs.printSecondaryReplicationInfo() 。 |
rs.reconfig() | |
rs.remove() | |
rs.status() | |
rs.stepDown() | |
rs.syncFrom() |
Sharding分片
sh.abortReshardCollection() | |
sh.addShard() | |
sh.addShardTag() | sh.addShardToZone() .sh.addShardToZone() 。 |
sh.addShardToZone() | |
sh.addTagRange() | sh.updateZoneKeyRange() .sh.updateZoneKeyRange() 。 |
sh.balancerCollectionStatus() | |
sh.commitReshardCollection() | |
sh.disableBalancing() | |
sh.enableBalancing() | sh.disableBalancing() .sh.disableBalancing() 禁用了分片集合平衡器进程,则激活该进程。 |
sh.disableAutoMerger() | |
sh.disableAutoSplit() | |
sh.enableAutoMerger() | |
sh.enableAutoSplit() | |
sh.enableSharding() | |
sh.getBalancerState() | |
sh.removeTagRange() | sh.removeRangeFromZone() .sh.removeRangeFromZone() 。 |
sh.removeRangeFromZone() | |
sh.help() | sh methods.sh 方法的帮助文本。 |
sh.isBalancerRunning() | |
sh.moveChunk() | |
sh.removeShardTag() | sh.removeShardFromZone() .sh.removeShardFromZone() 。 |
sh.removeShardFromZone() | |
sh.reshardCollection() | |
sh.setBalancerState() | |
sh.shardCollection() | |
sh.splitAt() | |
sh.splitFind() | |
sh.startAutoMerger() | |
sh.startBalancer() | |
sh.status() | db.printShardingStatus() .db.printShardingStatus() 。 |
sh.stopAutoMerger() | |
sh.stopBalancer() | |
sh.waitForBalancer() | |
sh.waitForBalancerOff() | |
sh.waitForPingChange() | mongos in the sharded cluster.mongos 的ping状态的更改。 |
sh.updateZoneKeyRange() | |
convertShardKeyToHashed() |
Free Monitoring免费监控
db.enableFreeMonitoring() | |
db.disableFreeMonitoring() | |
db.getFreeMonitoringStatus() |
Constructors构造函数
BinData() | |
BulkWriteResult() | Bulk.execute() .Bulk.execute() 中结果集的包装器。 |
Date() | |
ObjectId() | |
ObjectId.getTimestamp() | |
ObjectId.toString() | |
ObjectId.valueOf() | str attribute of an ObjectId as a hexadecimal string.str 属性显示为十六进制字符串。 |
UUID() | |
WriteResult() | |
WriteResult.hasWriteError() | WriteResult.writeError .WriteResult.writeError 。 |
WriteResult.hasWriteConcernError() | WriteResult.writeConcernError .WriteResult.writeConcernError 。 |
Connection连接
connect() | |
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.system 集合,不包括内部admin 数据库、local 数据库和config 数据库。 |
Session() | |
SessionOptions() |
Client-Side Field Level Encryption客户端字段级加密
The mongosh
client-side field level encryption methods require a database connection with client-side field level encryption enabled. mongosh
客户端字段级加密方法需要启用客户端字段级密码的数据库连接。If the current database connection was not initiated with client-side field level encryption enabled, either:如果当前数据库连接未在启用客户端字段级加密的情况下启动,请执行以下任一操作:
Use the使用Mongo()
constructor from themongosh
to establish a connection with the required client-side field level 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使用mongosh
command 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提供程序。
getKeyVault() | |
KeyVault.createDataKey() | KeyVault.createKey() .KeyVault.createKey() 的别名。 |
KeyVault.createKey() | |
KeyVault.deleteKey() | |
KeyVault.getKey() | |
KeyVault.getKeys() | |
KeyVault.addKeyAlternateName() | |
KeyVault.addKeyAltName() | KeyVault.addKeyAlternateName() .KeyVault.addKeyAlternateName() 的别名。 |
KeyVault.removeKeyAlternateName() | |
KeyVault.removeKeyAltName() | KeyVault.removeKeyAlternateName() .KeyVault.removeKeyAlternateName() 的别名。 |
KeyVault.getKeyByAltName() | |
KeyVault.rewrapManyDataKey() | |
getClientEncryption() | |
ClientEncryption.createEncryptedCollection() | |
ClientEncryption.encrypt() | |
ClientEncryption.decrypt() |
Atlas Search Index MethodsAtlas搜索索引方法
Atlas Search indexes let you query data in Atlas Search. Atlas Search索引允许您在Atlas Search中查询数据。Atlas Search indexes enable performant text search queries by mapping search terms to the documents that contain those terms.Atlas Search索引通过将搜索术语映射到包含这些术语的文档来实现高性能文本搜索查询。
Use the following methods to manage Atlas Search indexes.使用以下方法管理Atlas Search索引。
The following methods can only be run on deployments hosted on MongoDB Atlas, and require an Atlas cluster tier of at least M10.以下方法只能在MongoDB Atlas上托管的部署上运行,并且需要至少M10的Atlas集群层。
db.collection.createSearchIndex() | |
db.collection.dropSearchIndex() | |
db.collection.getSearchIndexes() | |
db.collection.updateSearchIndex() |