Embedded MongoDB Shell嵌入式MongoDB外壳¶
On this page
Starting in version 1.22, MongoDB Compass contains an embedded MongoDB Shell. 从1.22版开始,MongoDB Compass包含一个嵌入式MongoDB外壳。The MongoDB Shell is a fully functional JavaScript environment for interacting with MongoDB deployments. MongoDB Shell是一个功能齐全的JavaScript环境,用于与MongoDB部署交互。You can use the MongoDB Shell to test queries and operations directly with your database.您可以使用MongoDB Shell直接使用数据库测试查询和操作。
Open the Embedded MongoDB Shell打开嵌入式MongoDB外壳¶
To open the embedded MongoDB Shell, click MongoSH Beta along the bottom of MongoDB Compass.要打开嵌入式MongoDB外壳,请单击MongoDB Compass底部的“MongoSH Beta”。
Use the Embedded MongoDB Shell使用嵌入式MongoDB Shell¶
When you initially open the MongoDB Shell, it connects to the 最初打开MongoDB Shell时,它会连接到test
database. test
数据库。To switch to a different database, run the following command in the MongoDB Shell:要切换到其他数据库,请在MongoDB Shell中运行以下命令:
use <database name>
To run an operation in the embedded MongoDB Shell, type the operation into the shell and press Enter.要在嵌入式MongoDB Shell中运行操作,请在Shell中键入操作并按Enter键。
db.employees.find( { "last_name": "Smith" } )
Multi-Line Operations in the Embedded MongoDB Shell嵌入式MongoDB Shell中的多行操作¶
To write an operation that spans multiple lines in the embedded MongoDB Shell, press Shift + Enter to begin the next line of code.要在嵌入式MongoDB Shell中编写跨多行的操作,请按Shift+Enter开始下一行代码。
When you are finished writing your operation, press Enter to run it.编写完操作后,按Enter键运行该操作。
db.employees.aggregate( [ // press Shift + Enter
{ $match: { "last_name": "Smith" } } // press Shift + Enter
] ) // Press Enter
Learn More了解更多¶
The following links direct to the MongoDB Shell Documentation, which contains more complete reference for the MongoDB Shell, including syntax and behaviors.以下链接直接指向MongoDB Shell文档,其中包含有关MongoDB Shell的更完整参考,包括语法和行为。
Learn how to Perform CRUD Operations in the MongoDB Shell.了解如何在MongoDB Shell中执行CRUD操作。Learn how to Run Aggregation Pipelines in the MongoDB Shell.了解如何在MongoDB Shell中运行聚合管道。See a complete list of Available MongoDB Shell Methods.请参阅可用MongoDB Shell方法的完整列表。