For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Mongo.getURI() (mongosh method)

Mongo.getURI()
Returns:

The connection string for the current active connection.

See the Connection Strings for more information.

The command takes the following form:

db.getMongo().getURI()

You can use this method to return a URI string for a connection, which you can then use to create a new Mongo() instance:

new Mongo(db.getMongo().getURI())

To return the current connection string, enter the following:

db.getMongo().getURI()
mongodb://127.0.0.1:27019/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.4