Skip to content

Mongodb Connection Strings

"Mongodb Connection String" samples.

Standalone

mongodb://username:password@mongodb0.example.com:27017/?authSource=admin
Demo example:
mongodb://test_user:test_password@mongodb:27017/universityDB?authSource=admin

Replica Set

mongodb://username:password@mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?authSource=admin&replicaSet=myRepl

Sharded Cluster

mongodb://username:password@mongos0.example.com:27017,mongos1.example.com:27017,mongos2.example.com:27017/?authSource=admin

username: DB Username.

password: DB Password.

mongodb0.example.com: Mongodb server IP or DNS.

27017: Mongodb server default port.

DB_Name: DB name.

replicaSet: Replica Set name.

Ref_Link: Connection String URI Format