MongoDB Shell (mongosh
)
On this page本页内容
The MongoDB Shell, MongoDB Shell mongosh
, is a fully functional JavaScript and Node.js 16.x REPL environment for interacting with MongoDB deployments. mongosh
是一个功能齐全的JavaScript和Node.js 16x REPL环境,用于与MongoDB部署交互。You can use the MongoDB Shell to test queries and operations directly with your database.您可以使用MongoDB Shell直接使用数据库测试查询和操作。
mongosh
is available as a standalone package in the MongoDB Download Center.mongosh
在MongoDB下载中心作为一个独立的软件包提供。
Download and Install mongosh
下载并安装mongosh
mongosh
To learn how to download and install the 要了解如何下载和安装mongosh
binary, see Install mongosh
.mongosh
二进制文件,请参阅安装mongoh
。
Connect to a MongoDB Deployment连接到MongoDB部署
Once you have installed the MongoDB Shell and added it to your system 一旦安装了MongoDB Shell并将其添加到系统PATH
, you can connect to a MongoDB deployment. PATH
中,就可以连接到MongoDB部署。To learn more, see Connect to a Deployment.要了解更多信息,请参阅连接到部署。
The MongoDB Shell versus the Legacy mongo
ShellMongoDB Shell与Legacy mongo
Shell
mongo
ShellThe legacy 遗留的mongo
shell was deprecated in MongoDB 5.0 and removed in MongoDB 6.0. The new MongoDB Shell, mongosh
, offers numerous advantages over the legacy shell. mongo
shell在MongoDB 5.0中被弃用,在MongoDB 6.0中被删除。与传统Shell相比,新的MongoDB Shell mongosh
提供了许多优势。The new shell has improved:新外壳改进了:
compatibility with the MongoDB Node.js driver与MongoDB Node.js驱动程序的兼容性syntax highlighting语法突出显示command history命令历史记录logging测井
Some legacy methods are unavailable or have been replaced with updated methods in 一些遗留方法不可用,或者已被mongosh
. mongosh
中的更新方法所取代。To maintain backwards compatibility, the legacy methods that 为了保持向后兼容性,mongosh
supports use the same syntax as the corresponding methods in the mongo
shell.mongosh
支持的遗留方法使用与mongo
shell中相应方法相同的语法。
To see the complete list of methods supported by 要查看mongosh
, refer to: MongoDB Shell Methods.mongosh
支持的方法的完整列表,请参阅:MongoDB Shell方法。