Docs HomeMongoDB Shell

MongoDB Shell (mongosh)

The MongoDB Shell, mongosh, is a fully functional JavaScript and Node.js 16.x REPL environment for interacting with MongoDB deployments. MongoDB Shell 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.mongoshMongoDB下载中心作为一个独立的软件包提供。

Download and Install 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 PATH, you can connect to a MongoDB deployment. 一旦安装了MongoDB Shell并将其添加到系统PATH中,就可以连接到MongoDB部署。To learn more, see Connect to a Deployment.要了解更多信息,请参阅连接到部署

The MongoDB Shell versus the Legacy mongo ShellMongoDB Shell与Legacy mongo Shell

The 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支持的遗留方法使用与mongoshell中相应方法相同的语法。

To see the complete list of methods supported by mongosh, refer to: MongoDB Shell Methods.要查看mongosh支持的方法的完整列表,请参阅:MongoDB Shell方法

Learn More了解更多信息