Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old


Sets the URI.

Component Version macOS Windows Linux Server iOS SDK
MongoDB 12.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "MongoDB.SetURI"; MongoDBRef; URI )   More


Parameter Description Example
MongoDBRef The reference number for the mongo connection. $MongoDB
URI The URI to use. "mongodb://localhost/"


Returns OK or error.


Sets the URI.
Parses a string containing a MongoDB style URI connection string.
Returns an error in case of a parsing error.

Examples of some valid MongoDB connection strings can be seen below.

  • "mongodb://localhost/"
  • "mongodb://localhost/?replicaSet=myreplset"
  • "mongodb://myuser:mypass@localhost/"
  • "mongodb://"
  • "mongodb://[::1]:27017/"
  • "mongodb://,,[::1]:27019/?tls=true"
  • "mongodb://%2Ftmp%2Fmongodb-27017.sock"
  • "mongodb://user:pass@%2Ftmp%2Fmongodb-27017.sock"
  • "mongodb://localhost,[::1]/mydb?authSource=mydb"

If you like to use a SSH tunnel, you can create a tunnel with our SSH functions. Use SSH.Tunnel.Run to connect a local port with your remote server and the destination (usually port 27017). Then connect to localhost with the local port.


Connect to local server:

Set Variable [ $r ; Value: MBS( "MongoDB.SetURI"; $Mongo; "mongodb://localhost/" ) ]

Connect to local server with replication set and timeout:

Set Variable [ $r ; Value: MBS( "MongoDB.SetURI"; $Mongo; "mongodb://localhost/?replicaSet=rs0&connectTimeoutMS=300000" ) ]

Query options from URL:

Set Variable [ $Mongo ; Value: MBS( "MongoDB.New" ) ]
# set URL with options
Set Variable [ $r ; Value: MBS( "MongoDB.SetURI"; $Mongo; "mongodb://test@" & GetAsURLEncoded ( "/Users/cs/cacert.pem" )) ]
# query and show options
Set Variable [ $options ; Value: MBS( "MongoDB.GetOptions"; $Mongo ) ]
Show Custom Dialog [ "Options" ; $options ]
# success
Exit Script [ Text Result: $Mongo ]

Connect to online server for mongodb with certificate network:

Set Variable [ $r ; Value: MBS( "MongoDB.SetURI"; $Mongo; "mongodb+srv://" ) ]

See also

Example Databases

Blog Entries

This function checks for a license.

Created 22nd May 2022, last changed 6th August 2023

MongoDB.SetSSLOptions - MongoDB.SetUserName