This document provides an overview of the help available in 本文档概述了mongosh.mongosh中可用的帮助。
Tip
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:
helpDatabase Help数据库帮助
You can view database level information from inside the 您可以在mongosh console:mongosh控制台中查看数据库级别的信息:
By default 默认情况下,mongosh shows the current database in the prompt. You can also see the current database by running the db command:mongosh在提示符中显示当前数据库。您还可以通过运行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 dbs的别名。
Tip
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(). The following example returns help for the db.adminCommand() method:mongosh中特定数据库方法的帮助,请键入db.<method name>,后跟.help或.help()。以下示例返回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.adminCommandShow 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>,但您也可以使用泛型术语“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: /v8.3/reference/method/db.collection.insertOneShow 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>,但您也可以使用通用术语“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 HelpBSON课堂帮助
mongosh provides help methods for BSON classes. The help methods provide a brief overview of the BSON class and a link with more information.mongosh为BSON类提供了帮助方法。帮助方法提供了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:mongosh对.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
Log Method Help日志方法帮助
mongosh provides help for log message methods. To see available log message methods, run the following command:为日志消息方法提供帮助。要查看可用的日志消息方法,请运行以下命令:
log.help()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 | |
history() | |
show collections | |
show dbs |
|
show log <name> |
|
show logs | |
show profile | |
show roles | |
show tables | show collections.show collections。 |
show users |