Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 12.1   12.2   12.3   12.4   12.5   13.0   13.1   13.2   13.3   13.4    Statistic    FMM    Blog  

MongoDB.SetURI

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

Parameters

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

Result

Returns OK or error.

Description

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.


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.

Examples

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@1.2.3.4/?ssl=true&tlsCAFile=" & 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://test.6gtstkv.mongodb.net/?authSource=%24external&authMechanism=MONGODB-X509&retryWrites=true&w=majority&tlsCAFile=%2FUsers%2Ftest%2FMongoDB%20online%2Fcacert.pem&tlsCertificateKeyFile=%2FUsers%2Ftest%2FMongoDB%20online%2FX509-cert.pem" ) ]

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

💬 Ask a question or report a problem