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使用此命令可以测试mongoshhas 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()。