Building the Connection URL

Use the connection URL to supply connection information to the data store that you are accessing. The following is the format of a basic connection URL for the Simba MongoDB JDBC Driver, where [Host] is the DNS or IP address of the MongoDB server and [Database] is the name of the database that you are connecting to:

jdbc:mongodb://[Host]/[Database]

If IPv6 is used as the Host, enclose the value between square brackets. For example:

jdbc:mongodb://[fe80::1952:2aef:b93d:1532]:27017/[Database]

By default, the connector connects to port 27017.

You can also specify optional settings such as the number of the TCP port to connect to, your credentials for authentication, or any of the connection properties supported by the connector. For a list of the properties available in the connector, see Driver Configuration Options on page 1.

The following is the format of a connection URL that specifies some optional settings:

jdbc:mongodb://[UserName]:[Password]@[Host]:[Port]/[Database]?[Property1]=[Value]&[Property2]=[Value]&...

For example, to connect to port 18000 on a MongoDB server installed on the local machine, connect to a database named TeamRoster, use the schema definition stored in the database, and authenticate the connection using the SCRAM-SHA-1 protocol, you would use the following connection URL:

jdbc:mongodb://jsmith:pass12345@localhost:18000/TeamRoster?AuthMechanism=SCRAM-SHA-1&LoadMetadataTable=true

Important:

Important:

  • Properties are case-sensitive.
  • Do not duplicate properties in the connection URL.

Connecting to Replica Sets

To connect to a replica set, you can specify one of the servers in the set and then use the ReplicaSet property to specify the name of the replica set. For example:

jdbc:mongodb://jsmith:pass12345@192.168.1.1:47017/TeamRoster?AuthMechanism=SCRAM-SHA-1&LoadMetadataTable=true&ReplicaSet=TestSet

Alternatively, you can provide the information for all the servers in a comma-separated list. For example:

jdbc:mongodb://jsmith:pass12345@192.168.1.1:47017, 192.168.1.1:47018, 192.168.1.1:47019/TeamRoster?AuthMechanism=SCRAM-SHA-1&LoadMetadataTable=true

Connecting to DNS SRV

To connect to a MongoDB cluster that was configured with a DNS constructed seedlist, specify the host name to be provided in the connection string that corresponds to a DNS SRV record. For example:

jdbc:mongodb://[UserName]:[Password]@[Hostname]/[Database]?AuthMechanism=SCRAM-SHA-1;UseSrvConnection=true