Database Methods数据库方法

Note注意

For details on specific methods, including syntax and examples, click on the specific method to go to its reference page.有关特定方法(包括语法和示例)的详细信息,请单击特定方法以转到其参考页。

Name名称Description描述
db.adminCommand()Runs a command against the admin database.admin数据库运行命令。
db.aggregate()Runs admin/diagnostic pipeline which does not require an underlying collection.运行不需要基础集合的管理/诊断管道。
db.cloneDatabase()Deprecated. 已弃用Copies a database from a remote host to the current host when run against MongoDB 4.0 or earlier. 在MongoDB 4.0或更早版本上运行时,将数据库从远程主机复制到当前主机。Unsupported when run against MongoDB 4.2 or later.在MongoDB 4.2或更高版本上运行时不受支持。
db.commandHelp()Returns help information for a database command.返回数据库命令的帮助信息。
db.copyDatabase()Deprecated. 已弃用Copies a database to another database on the current host when run against MongoDB 4.0 or earlier. 在MongoDB 4.0或更早版本上运行时,将数据库复制到当前主机上的另一个数据库。Unsupported when run against MongoDB 4.2 or later.在MongoDB 4.2或更高版本上运行时不受支持。
db.createCollection()Creates a new collection or a view. 创建新集合或视图。Commonly used to create a capped collection.通常用于创建有上限的集合。
db.createView()Creates a view.创建视图。
db.currentOp()Reports the current in-progress operations.报告当前正在进行的操作。
db.dropDatabase()Removes the current database.删除当前数据库。
db.fsyncLock()Flushes writes to disk and locks the database to prevent write operations and assist backup operations. 刷新对磁盘的写入并锁定数据库,以防止写入操作并协助备份操作。Wraps fsync.包装fsync
db.fsyncUnlock()Allows writes to continue on a database locked with db.fsyncLock().允许在使用db.fsyncLock()锁定的数据库上继续写入。
db.getCollection()Returns a collection or view object. 返回集合或视图对象。Used to access collections with names that are not valid in mongosh.用于访问名称在mongosh中无效的集合。
db.getCollectionInfos()Returns collection information for all collections and views in the current database.返回当前数据库中所有集合和视图的集合信息。
db.getCollectionNames()Lists all collections and views in the current database.列出当前数据库中的所有集合和视图。
db.getLogComponents()Returns the log message verbosity levels.返回日志消息详细级别。
db.getMongo()Returns the Mongo() connection object for the current connection.返回当前连接的Mongo()连接对象。
db.getName()Returns the name of the current database.返回当前数据库的名称。
db.getProfilingStatus()Returns a document that reflects the current profiling level and the profiling threshold.返回反映当前分析级别和分析阈值的文档。
db.getReplicationInfo()Returns a document with replication statistics.返回包含复制统计信息的文档。
db.getSiblingDB()Provides access to the specified database.提供对指定数据库的访问。
db.hello()Returns a document that reports the state of the replica set.返回报告副本集状态的文档。
db.help()Displays descriptions of common db object methods.显示常用db对象方法的说明。
db.hostInfo()Returns a document with information about the system MongoDB runs on. 返回包含MongoDB运行系统信息的文档。Wraps 包装hostInfo
db.killOp()Terminates a specified operation.终止指定的操作。
db.listCommands()Displays a list of common database commands.显示常用数据库命令的列表。
db.logout()Deprecated. 已弃用Ends an authenticated session.结束经过身份验证的会话。
db.printCollectionStats()Prints statistics from every collection. 打印每个集合的统计数据。Wraps db.collection.stats().包装db.collection.stats()
db.printReplicationInfo()Prints a formatted report of the replica set status from the perspective of the primary.从主副本的角度打印副本集状态的格式化报告。
db.printSecondaryReplicationInfo()Prints a formatted report of the replica set status from the perspective of the secondaries.从辅助设备的角度打印副本集状态的格式化报告。
db.printShardingStatus()Prints a report of the sharding configuration and the chunk ranges.打印分片配置和块范围的报告。
db.printSlaveReplicationInfo()

Deprecated since version 4.4.1:自版本4.4.1起已弃用: Use db.printSecondaryReplicationInfo() instead.请改用db.printSecondaryReplicationInfo()

db.resetError()Removed in MongoDB 5.0.在MongoDB 5.0中删除。 Resets the last error status.重置上次错误状态。
db.rotateCertificates()Performs online TLS certificate rotation. 执行在线TLS证书轮换。Wraps rotateCertificates.包装rotateCertificates
db.runCommand()Runs a database command.运行数据库命令
db.serverBuildInfo()Returns a document that displays the compilation parameters for the mongod instance. 返回显示mongod实例编译参数的文档。Wraps buildInfo.包装buildInfo
db.serverCmdLineOpts()Returns a document with information about the runtime used to start the MongoDB instance. 返回包含用于启动MongoDB实例的运行时信息的文档。Wraps getCmdLineOpts.包装getCmdLineOpts
db.serverStatus()Returns a document that provides an overview of the state of the database process.返回提供数据库进程状态概述的文档。
db.setLogLevel()Sets a single log message verbosity level.设置单个日志消息详细级别。
db.setProfilingLevel()Modifies the current level of database profiling.修改数据库分析的当前级别。
db.shutdownServer()Shuts down the current mongod or mongos process cleanly and safely.干净安全地关闭当前mongodmongos进程。
db.stats()Returns a document that reports on the state of the current database.返回报告当前数据库状态的文档。
db.version()Returns the version of the mongod instance.返回mongod实例的版本。
db.watch()Opens a change stream cursor for a database to report on all its non-system collections. 打开数据库的更改流游标,以报告其所有非system集合。Cannot be opened on the admin, local or config databases.无法在adminlocalconfig数据库上打开。
←  cursor.toArray()db.adminCommand() →