mongoshOn this page本页内容
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 specific methods, including syntax and examples, click on the specific method to go to its reference page.有关特定方法(包括语法和示例)的详细信息,请单击特定方法以转到其参考页。
| db.collection.aggregate() | |
| db.collection.bulkWrite() | |
| db.collection.count() | countto return a count of the number of documents in a collection or a view.count以返回集合或视图中文档数的计数。 | 
| db.collection.countDocuments() | $groupaggregation stage with a$sumexpression 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() | sizefield in the output of thecollStats.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() | countto 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() | storageSizefield of thecollStatsoutput.collStats输出的storageSize字段周围提供包装。 | 
| db.collection.totalIndexSize() | totalIndexSizefield of thecollStatsoutput.collStats输出的totalIndexSize字段周围提供包装。 | 
| db.collection.totalSize() | |
| db.collection.unhideIndex() | |
| db.collection.updateOne() | |
| db.collection.updateMany() | |
| db.collection.watch() | |
| db.collection.validate() | 
| 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() | trueif 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() | trueif 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()andlimit()methods.skip()和limit()方法后,返回游标中文档的计数。 | 
| cursor.skip() | |
| cursor.sort() | |
| cursor.tailable() | |
| cursor.toArray() | 
| db.adminCommand() | admindatabase.admin数据库运行命令。 | 
| db.aggregate() | |
| db.cloneDatabase() | |
| db.commandHelp() | |
| db.copyDatabase() | |
| 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() | dbobject methods.db对象方法的说明。 | 
| db.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.resetError() | |
| db.rotateCertificates() | rotateCertificates.rotateCertificates。 | 
| db.runCommand() | |
| db.serverBuildInfo() | mongodinstance.mongod实例的编译参数。buildInfo.buildInfo。 | 
| db.serverCmdLineOpts() | getCmdLineOpts.getCmdLineOpts。 | 
| db.serverStatus() | |
| db.setLogLevel() | |
| db.setProfilingLevel() | |
| db.shutdownServer() | mongodormongosprocess cleanly and safely.mongod或mongos进程。 | 
| db.stats() | |
| db.version() | mongodinstance.mongod实例的版本。 | 
| db.watch() | systemcollections.admin,localorconfigdatabases.admin、local或config数据库上打开。 | 
| 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.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() | updateorupdateOneoperation.update或updateOne操作更新的数组元素。 | 
| Bulk.find.collation() | |
| Bulk.find.hint() | |
| Bulk.find.remove() | |
| Bulk.find.removeOne() | |
| Bulk.find.replaceOne() | |
| Bulk.find.updateOne() | |
| Bulk.find.update() | multiupdate operation to a list of operations.multi更新操作添加到操作列表中。 | 
| Bulk.find.upsert() | upsert: truefor 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()结果。 | 
| db.auth() | |
| db.changeUserPassword() | |
| db.createUser() | |
| db.dropUser() | |
| db.dropAllUsers() | |
| db.getUser() | |
| db.getUsers() | |
| db.grantRolesToUser() | |
| db.removeUser() | |
| db.revokeRolesFromUser() | |
| db.updateUser() | |
| passwordPrompt() | mongoshuser authentication/management methods.mongosh用户身份验证/管理方法中直接指定密码。 | 
| db.createRole() | |
| db.dropRole() | |
| db.dropAllRoles() | |
| db.getRole() | |
| db.getRoles() | |
| db.grantPrivilegesToRole() | |
| db.revokePrivilegesFromRole() | |
| db.grantRolesToRole() | |
| db.revokeRolesFromRole() | |
| db.updateRole() | 
| rs.add() | |
| rs.addArb() | |
| rs.conf() | |
| rs.freeze() | |
| rs.help() | |
| rs.initiate() | |
| rs.printReplicationInfo() | |
| rs.printSecondaryReplicationInfo() | |
| rs.printSlaveReplicationInfo() | 
 | 
| rs.reconfig() | |
| rs.remove() | |
| rs.status() | |
| rs.stepDown() | |
| rs.syncFrom() | 
| 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.disableAutoSplit() | |
| sh.enableAutoSplit() | |
| sh.enableSharding() | |
| sh.getBalancerHost() | |
| sh.getBalancerState() | |
| sh.removeTagRange() | sh.removeRangeFromZone().sh.removeRangeFromZone()。 | 
| sh.removeRangeFromZone() | |
| sh.help() | shmethods.sh方法的帮助文本。 | 
| sh.isBalancerRunning() | |
| sh.moveChunk() | |
| sh.removeShardTag() | sh.removeShardFromZone().sh.removeShardFromZone()。 | 
| sh.removeShardFromZone() | |
| sh.reshardCollection() | 
 
 | 
| sh.setBalancerState() | |
| sh.shardCollection() | |
| sh.splitAt() | |
| sh.splitFind() | |
| sh.startBalancer() | |
| sh.status() | db.printShardingStatus().db.printShardingStatus()。 | 
| sh.stopBalancer() | |
| sh.waitForBalancer() | |
| sh.waitForBalancerOff() | |
| sh.waitForPingChange() | mongosin the sharded cluster.mongos的ping状态发生变化。 | 
| sh.updateZoneKeyRange() | |
| convertShardKeyToHashed() | 
| db.enableFreeMonitoring() | |
| db.disableFreeMonitoring() | |
| db.getFreeMonitoringStatus() | 
| BulkWriteResult() | Bulk.execute().Bulk.execute()的结果集。 | 
| Date() | |
| ObjectId() | |
| ObjectId.getTimestamp() | |
| ObjectId.toString() | |
| ObjectId.valueOf() | strattribute of an ObjectId as a hexadecimal string.str属性显示为十六进制字符串。 | 
| UUID() | |
| WriteResult() | |
| WriteResult.hasWriteError() | WriteResult.writeError.WriteResult.writeError。 | 
| WriteResult.hasWriteConcernError() | WriteResult.writeConcernError.WriteResult.writeConcernError。 | 
| connect() | |
| Mongo() | |
| Mongo.getDB() | |
| Mongo.getReadPrefMode() | |
| Mongo.getReadPrefTagSet() | |
| Mongo.setCausalConsistency() | |
| Mongo.setReadPref() | |
| Mongo.startSession() | |
| Mongo.watch() | systemcollections across all its databases, excluding the internaladmin,local, andconfigdatabases.admin、local和config数据库)中的所有非系统集合。 | 
| Session() | |
| SessionOptions() | 
| cat() | |
| cd() | |
| copyDbpath() | dbPath.dbPath。 | 
| getHostName() | mongosh.mongosh的系统的主机名。 | 
| getMemInfo() | |
| hostname() | |
| isInteractive() | mongoshis running in interactive or script mode.mongosh是以交互模式还是脚本模式运行。 | 
| listFiles() | |
| load() | |
| ls() | |
| md5sumFile() | |
| mkdir() | |
| pwd() | |
| quit() | |
| removeFile() | |
| resetDbpath() | dbPath.dbPath。 | 
| sleep() | mongoshfor a given period of time.mongosh一段时间。 | 
| setVerboseShell() | mongoshto report operation timing.mongosh配置为报告操作计时。 | 
| version() | mongoshinstance.mongosh实例的当前版本。 | 
| _isWindows() | trueif the shell runs on a Windows system;falseif a Unix or Linux system.true;如果是Unix或Linux系统,则为false。 | 
| _rand() | 0and1. | 
The mongo client-side field level encryption methods require a database connection with client-side field level encryption enabled. mongo客户端字段级加密方法需要启用客户端字段级加密的数据库连接。If the current database connection was not initiated with client-side field level encryption enabled, either:如果当前数据库连接未在启用客户端字段级加密的情况下启动,请执行以下任一操作:
Use the 使用Mongo() constructor from the mongo shell to establish a connection with the required client-side field level encryption options. Mongo() shell中的Mongo()构造函数与所需的客户端字段级加密选项建立连接。The Mongo() method supports the following Key Management Service (KMS) providers for Customer Master Key (CMK) management:Mongo()方法支持以下密钥管理服务(KMS)提供程序用于客户主密钥(CMK)管理:
or
mongo shell command line options to establish a connection with the required options. mongo shell命令行选项与所需选项建立连接。| getKeyVault() | |
| KeyVault.createKey() | |
| KeyVault.deleteKey() | |
| KeyVault.getKey() | |
| KeyVault.getKeys() | |
| KeyVault.addKeyAlternateName() | |
| KeyVault.removeKeyAlternateName() | |
| KeyVault.getKeyByAltName() | |
| getClientEncryption() | |
| ClientEncryption.encrypt() | |
| ClientEncryption.decrypt() |