Database Manual / Reference / mongosh Methods

Database Methods数据库方法

Note

For details on a specific method, including syntax and examples, click on the link to the method's 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.commandHelp()Returns help information for a database command.返回数据库命令的帮助信息。
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.rotateCertificates()Performs online TLS certificate rotation. Wraps rotateCertificates.执行在线TLS证书轮换。包装rotateCertificates
db.runCommand()Runs a database command.运行数据库命令
db.serverBuildInfo()Returns a document that displays the compilation parameters for the mongod instance. Wraps buildInfo.返回一个文档,显示mongod实例的编译参数。包装buildInfo
db.serverCmdLineOpts()Returns a document with information about the runtime used to start the MongoDB instance. Wraps getCmdLineOpts.返回一个文档,其中包含用于启动MongoDB实例的运行时信息。包装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. Cannot be opened on the admin, local or config databases.打开数据库的更改流游标,以报告其所有非系统集合。无法在adminlocalconfig数据库上打开。