Docs HomeMongoDB Manual

db.getMongo()

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

db.getMongo()
Returns:返回值:The current database connection.当前数据库连接。

db.getMongo() runs when the shell initiates. 当shell启动时运行。Use this command to test that mongosh has a connection to the proper database instance.使用此命令可以测试mongosh是否连接到正确的数据库实例。

Note

The legacy mongo shell has a sub-command, db.getMongo().setSecondaryOk(), which is not available in mongosh. 传统的mongoshell有一个子命令db.getMongo().setSecondaryOk(),这在mongosh中是不可用的。In mongosh, use Mongo.setReadPref() instead.mongosh中,请改用Mongo.setReadPref()