Description描述
Mongo.getDB(<database>)Provides access to database objects from提供从mongoshor from a JavaScript file.mongosh或JavaScript文件访问数据库对象的功能。TheMongo.getDB()method has the following parameter:Mongo.getDB()方法有以下参数:Parameter参数Type类型Description描述databasestring字符串The name of the database to access.要访问的数据库的名称。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Example示例
The following example instantiates a new connection to the MongoDB instance running on the localhost interface and returns a reference to 以下示例实例化到在localhost接口上运行的MongoDB实例的新连接,并返回对"myDatabase":"myDatabase"的引用:
db = new Mongo().getDB("myDatabase");