mongo ShellOn this page本页内容
JavaScript in MongoDB
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 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.copyTo() |
|
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.estimatedDocumentCount() |
count to return an approximate count of the documents in a collection or a view.count以返回集合或视图中文档的大致计数。 |
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.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.insert() |
|
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.save() |
insert() and update() to insert new documents.insert()和update()周围提供包装器以插入新文档。 |
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.update() |
|
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() |
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() |
db.adminCommand() |
admin database.admin数据库运行命令。 |
db.aggregate() |
|
db.cloneDatabase() |
|
db.commandHelp() |
|
db.copyDatabase() |
|
db.createCollection() |
|
db.createView() |
|
db.currentOp() |
|
db.dropDatabase() |
|
db.eval() |
|
db.fsyncLock() |
fsync.fsync |
db.fsyncUnlock() |
db.fsyncLock().db.fsyncLock()锁定的数据库上继续写入。 |
db.getCollection() |
mongo shell.mongo shell中无效的集合。 |
db.getCollectionInfos() |
|
db.getCollectionNames() |
|
db.getLastError() |
getLastError.getLastError。 |
db.getLastErrorObj() |
getLastError.getLastError。 |
db.getLogComponents() |
|
db.getMongo() |
Mongo() connection object for the current connection.Mongo()连接对象。 |
db.getName() |
|
db.getProfilingLevel() |
|
db.getProfilingStatus() |
|
db.getReplicationInfo() |
|
db.getSiblingDB() |
|
db.help() |
db object methods.db对象方法的说明。 |
db.hostInfo() |
hostInfohostInfo |
db.isMaster() |
|
db.killOp() |
|
db.listCommands() |
|
db.logout() |
|
db.printCollectionStats() |
db.collection.stats().db.collection.stats()。 |
db.printReplicationInfo() |
|
db.printShardingStatus() |
|
db.printSlaveReplicationInfo() |
|
db.resetError() |
|
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数据库上打开。 |
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() |
update or updateOne operation.update或updateOne操作更新的数组元素。 |
Bulk.find.collation() |
|
Bulk.find.hint() |
|
Bulk.find.remove() |
|
Bulk.find.removeOne() |
|
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()操作对象中的操作数和批数的JSON文档。 |
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() |
mongo shell user authentication/management methods.mongo shell用户身份验证/管理方法中直接指定密码。 |
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.printSlaveReplicationInfo() |
|
rs.reconfig() |
|
rs.remove() |
|
rs.secondaryOk() |
|
rs.status() |
|
rs.stepDown() |
|
rs.syncFrom() |
sh.addShard() |
|
sh.addShardTag() |
sh.addShardToZone().sh.addShardToZone()。 |
sh.addShardToZone() |
|
sh.addTagRange() |
sh.updateZoneKeyRange().sh.updateZoneKeyRange()。 |
sh.balancerCollectionStatus() |
|
sh.disableBalancing() |
|
sh.enableBalancing() |
sh.disableBalancing().sh.disablebalancement()禁用切分收集平衡器进程,则激活该进程。 |
sh.disableAutoSplit() |
|
sh.enableAutoSplit() |
|
sh.enableSharding() |
|
sh.getBalancerHost() |
|
sh.getBalancerState() |
|
sh.removeTagRange() |
sh.removeRangeFromZone().sh.RemoveAngeFromZone()。 |
sh.removeRangeFromZone() |
|
sh.help() |
sh methods.sh方法的帮助文本。 |
sh.isBalancerRunning() |
|
sh.moveChunk() |
|
sh.removeShardTag() |
sh.removeShardFromZone().sh.removeShardFromZone()。 |
sh.removeShardFromZone() |
|
sh.setBalancerState() |
|
sh.shardCollection() |
|
sh.splitAt() |
|
sh.splitFind() |
|
sh.startBalancer() |
|
sh.status() |
db.printShardingStatus().db.printShardingStatus()。 |
sh.stopBalancer() |
|
sh.waitForBalancer() |
|
sh.waitForBalancerOff() |
|
sh.waitForPingChange() |
mongos in 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() |
str attribute 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.getSecondaryOk() |
|
Mongo.isCausalConsistency() |
|
Mongo.setCausalConsistency() |
|
Mongo.setReadPref() |
|
Mongo.setSecondaryOk() |
|
Mongo.startSession() |
|
Mongo.watch() |
system collections across all its databases, excluding the internal admin, local, and config databases.admin、local和config数据库)中的所有非system集合。 |
Session |
|
SessionOptions |
| cat() | |
| cd() | |
copyDbpath() |
dbPath.dbPath。 |
getHostName() |
mongo shell. |
getMemInfo() |
|
| hostname() | |
| isInteractive() | mongo shell is running in interactive or script mode.mongo shell是以交互模式还是脚本模式运行。 |
listFiles() |
|
| load() | |
| ls() | |
md5sumFile() |
|
| mkdir() | |
| pwd() | |
| quit() | |
removeFile() |
|
resetDbpath() |
dbPath. |
| sleep() | mongo shell for a given period of time.mongo shell挂起一段给定的时间。 |
setVerboseShell() |
mongo shell to report operation timing.mongo shell配置为报告操作时间。 |
| version() | mongo shell instance.mongo shell实例的当前版本。 |
_isWindows() |
true if the shell runs on a Windows system; false if a Unix or Linux system.true;如果是Unix或Linux系统,则为false。 |
_rand() |
0 and 1.0和1之间的随机数。 |
Note
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:如果当前数据库连接未在启用客户端字段级加密的情况下启动,则:
Mongo() constructor from the mongo shell to establish a connection with the required client-side field level encryption options.Mongo()构造函数与所需的客户端字段级加密选项建立连接。Mongo() method supports both Amazon Web Services and Local Key Management Service (KMS) providers for Customer Master Key (CMK) management.Mongo()方法支持Amazon Web服务和本地密钥管理服务(KMS)提供程序,用于客户主密钥(CMK)管理。
or
mongo shell command line options to establish a connection with the required options.mongoshell命令行选项建立与所需选项的连接。getKeyVault() |
|
KeyVault.createKey() |
|
KeyVault.deleteKey() |
|
KeyVault.getKey() |
|
KeyVault.getKeys() |
|
KeyVault.addKeyAlternateName() |
|
KeyVault.removeKeyAlternateName() |
|
KeyVault.getKeyByAltName() |
|
getClientEncryption() |
|
ClientEncryption.encrypt() |
|
ClientEncryption.decrypt() |