mongosh Help
On this page本页内容
This document provides an overview of the help available in 本文档概述了mongosh.mongosh中提供的帮助。
When accessing help in 在mongosh, you can use the .help() and .help syntaxes interchangeably.mongosh中访问帮助时,可以交替使用help()和.help语法。
Command Line Help命令行帮助
To see the options for running the 要查看运行mongosh executable and connecting to a deployment, use the --help option from the command line:mongosh可执行文件和连接到部署的选项,请在命令行中使用--help选项:
mongosh --helpmongosh Shell Help
To see the list of commands available in the 要查看mongosh console, type help inside a running mongosh console:mongosh控制台中可用的命令列表,请在正在运行的mongosh主机中键入help:
help
Database Help数据库帮助
You can view database level information from inside the 您可以从mongosh console:mongosh控制台内部查看数据库级别的信息:
By default 默认情况下,mongosh shows the current database in the prompt. mongosh会在提示中显示当前数据库。You can also see the current database by running the 您还可以通过运行db command:db命令查看当前数据库:
db
Show Available Databases显示可用数据库
To see the list of databases available to you on the server, use the 要查看服务器上可用的数据库列表,请使用show dbs command:show dbs命令:
show dbs
show databases is an alias for show dbs.show databases是show dbs的别名。
The list of databases will change depending on your access authorizations. 数据库列表将根据您的访问权限而更改。For more information on access restrictions for viewing databases, see 有关查看数据库的访问限制的详细信息,请参阅listDatabases.listDatabases。
Show Database Methods显示数据库方法
To see the list of database methods you can use on the 要查看可以在db object, run db.help():db对象上使用的数据库方法列表,请运行db.help():
db.help()
The output resembles the following abbreviated list:输出类似于以下缩写列表:
Database Class:
getMongo Returns the current database connection
getName Returns the name of the DB
getCollectionNames Returns an array containing the names of all collections in the current database.
getCollectionInfos Returns an array of documents with collection information, i.e. collection name and options, for the current database.
runCommand Runs an arbitrary command on the database.
adminCommand Runs an arbitrary command against the admin database.
...
Show Help for a Specific Database Method显示特定数据库方法的帮助
To see help for a specific database method in 要查看mongosh, type the db.<method name>, followed by .help or .help(). mongosh中特定数据库方法的帮助,请键入db.<method name>,后跟.help或.help()。The following example returns help for the 以下示例返回db.adminCommand() method:db.adminCommand()方法的帮助:
db.adminCommand.help()
The output resembles the following:输出类似于以下内容:
db.adminCommand({ serverStatus: 1 }):
Runs an arbitrary command against the admin database.
For more information on usage: https://www.mongodb.com/docs/manual/reference/method/db.adminCommand
Show Additional Usage Details for a Database Method显示数据库方法的其他用法详细信息
To see additional usage details for a database method in 要查看mongosh, type the db.<method name> without the parenthesis (()). mongosh中数据库方法的其他用法详细信息,请键入db.<method name>,不带括号(())。The following example returns details about the 以下示例返回有关db.adminCommand() method:db.adminCommand()方法的详细信息:
db.adminCommand
The output resembles the following:输出类似于以下内容:
[Function: adminCommand] AsyncFunction {
apiVersions: [ 1, Infinity ],
serverVersions: [ '3.4.0', '999.999.999' ],
returnsPromise: true,
topologies: [ 'ReplSet', 'Sharded', 'LoadBalanced', 'Standalone' ],
returnType: { type: 'unknown', attributes: {} },
deprecated: false,
platforms: [ 0, 1, 2 ],
isDirectShellCommand: false,
acceptsRawInput: false,
shellCommandCompleter: undefined,
help: [Function (anonymous)] Help
}
Collection Help集合帮助
You can view collection level information from inside the 您可以从mongosh console.mongosh控制台内部查看集合级别的信息。
These help methods accept a collection name, 这些帮助方法接受集合名称<collection>, but you can also use the generic term, "collection", or even a collection that does not exist.<collection>,但您也可以使用通用术语“集合”,甚至可以使用不存在的集合。
List Collections in the Current Database列出当前数据库中的集合
To see the list of collections in the current database, use the 要查看当前数据库中的集合列表,请使用show collections command:show collections命令:
show collections
The show collections output indicates if a collection is a time series collection or a read-only view.show collections输出指示集合是时间序列集合还是只读视图。
managementFeedback [view]
survey
weather [time-series]
system.buckets.weather
system.views
In the preceding example:在前面的示例中:
managementFeedbackis a view是视图weatheris a time series是时间序列surveyis a collection是一个集合system.buckets.weatheris a system generated collection that supports the是系统生成的集合,支持weathertime seriesweather时间序列system.viewsis a system generated collection that supports views on other collections是系统生成的集合,支持其他集合上的视图
Show Collection Methods显示集合方法
To see the list of methods available on collection objects use the 若要查看集合对象上可用方法的列表,请使用数据库db.<collection>.help() method:db.<collection>.help()方法:
db.collection.help()
<collection> can be the name of an existing or non-existent collection.可以是现有集合或不存在集合的名称。
The output resembles the following abbreviated list:输出类似于以下缩写列表:
Collection Class:
aggregate Calculates aggregate values for the data in a collection or a view.
bulkWrite Performs multiple write operations with controls for order of execution.
count Returns the count of documents that would match a find() query for the collection or view.
countDocuments Returns the count of documents that match the query for a collection or view.
deleteMany Removes all documents that match the filter from a collection.
deleteOne Removes a single document from a collection.
...
Show Help for a Specific Collection Method显示特定集合方法的帮助
To see help for a specific collection method in 要查看mongosh, use db.<collection>.<method name>, followed by .help or .help().mongosh中特定集合方法的帮助,请使用db.<collection>.<method name>,后跟.help或.help()。
The following example displays help for 以下示例显示db.collection.insertOne():db.collection.insertOne()的帮助:
db.collection.insertOne.help()
The output resembles the following:输出类似于以下内容:
db.collection.insertOne(document, options):Inserts a document into a collection.将文档插入集合中。
For more information on usage: https://www.mongodb.com/docs/manual/reference/method/db.collection.insertOne
Show Additional Details for a Collection Method显示集合方法的其他详细信息
To see additional details for a collection method type the method name, 若要查看集合方法的其他详细信息,请键入db.<collection>.<method>, without the parenthesis (()).db.<collection>.<method>,不带括号(())。
The following example returns details about the 以下示例返回有关insertOne() method:insertOne()方法的详细信息:
db.collection.insertOne
The output resembles the following:输出类似于以下内容:
[Function: insertOne] AsyncFunction {
apiVersions: [ 1, Infinity ],
serverVersions: [ '3.2.0', '999.999.999' ],
returnsPromise: true,
topologies: [ 'ReplSet', 'Sharded', 'LoadBalanced', 'Standalone' ],
returnType: { type: 'unknown', attributes: {} },
deprecated: false,
platforms: [ 0, 1, 2 ],
isDirectShellCommand: false,
acceptsRawInput: false,
shellCommandCompleter: undefined,
help: [Function (anonymous)] Help
}Cursor Help游标帮助
To modify read operations that use 要修改使用find(), use cursor methods.find()的读取操作,请使用游标方法。
To list the available modifier and cursor handling methods, use the 要列出可用的修饰符和游标处理方法,请使用db.collection.find().help() command:db.collection.find().help()命令:
db.collection.find().help()
This help call accepts a collection name, 此帮助调用接受集合名称<collection>, but you can also use the generic term, "collection", or even a collection which does not exist.<collection>,但您也可以使用通用术语“集合”,甚至可以使用不存在的集合。
Some useful methods for handling cursors are:处理游标的一些有用方法有:
hasNext()checks if the cursor has more documents.检查游标是否有更多文档。next()returns the next document and moves the cursor position forward by one.返回下一个文档,并将游标位置向前移动一个。forEach(<function>)applies the将<function>to each document returned by the cursor.<function>应用于游标返回的每个文档。
For a list of available cursor methods, see Cursor.有关可用游标方法的列表,请参阅游标。
BSON Class Help
mongosh provides help methods for BSON classes. 提供了BSON类的帮助方法。The help methods provide a brief overview of the BSON class and a link with more information.help方法提供了BSON类的简要概述以及包含更多信息的链接。
To access help for BSON classes, run 要访问BSON类的帮助,请对类名或类的实例化实例运行.help() on either the class name or an instantiated instance of the class:.help():
<BSON class>.help()
// or
<BSON class>().help()
For example, to view help for the 例如,要查看ObjectId BSON class, run one of the following commands:ObjectId BSON类的帮助,请运行以下命令之一:
ObjectId.help()
ObjectId().help()
mongosh returns the same output for both 为两个.help() methods:.help()方法返回相同的输出:
The ObjectId BSON Class:
For more information on usage: https://mongodb.github.io/node-mongodb-native/3.6/api/ObjectID.html
mongosh provides help methods for the following BSON classes:为以下BSON类提供了帮助方法:
BinDataCodeDBRefMinKeyMaxKeyNumberDecimalNumberIntNumberLongObjectIdSymbol(Deprecated)Timestamp
Command Helpers命令帮助程序
mongosh provides the following methods and commands to wrap certain database commands and obtain information on your deployment:提供了以下方法和命令来包装某些数据库命令并获取有关部署的信息:
db.help() | |
db.<collection>.help() | <collection> can be the name of an existing collection or a non-existing collection.<collection>可以是现有集合的名称,也可以是不存在的集合的名称。 |
help | |
show collections | |
show dbs | Note
|
show log <name> | <name>, the command defaults to global.<name>,则该命令默认为global。startupWarning logs, run:startupWarning日志,请运行:
show log startupWarnings |
show logs | |
show profile | |
show roles | |
show tables | show collections.show collections。 |
show users |