Mongo.getDB()

On this page本页内容

Description描述

Mongo.getDB(<database>)

Provides access to database objects from mongosh or from a JavaScript file.提供从mongosh或JavaScript文件访问数据库对象的权限。

The Mongo.getDB() method has the following parameter:Mongo.getDB()方法具有以下参数:

Parameter参数Type类型Description描述
databasestringThe name of the database to access.要访问的数据库的名称。

Example示例

The following example instantiates a new connection to the MongoDB instance running on the localhost interface and returns a reference to "myDatabase":以下示例实例化与在localhost接口上运行的MongoDB实例的新连接,并返回对"myDatabase"的引用:

db = new Mongo().getDB("myDatabase");
Tip提示
See also: 参阅:
←  Mongo()Mongo.getDBNames() →