Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding MongoDb connection strings

I am working with Mongodb as a database for my asp.net mvc front end site. I have MongoDB running on 3 servers, in a replica set, a primary, secondary and an arbiter. Connecting to this is the 3 front end web servers that performs CRUD operations on the data held in Mongo. I have a number of questions on my setup that I would like clarification on.

This is my connection string from C#

server=myprimary.com:27017,mysecondary.com:27017;replicaset=MySet;safe=true;database=MyDatabase

Is it correct not to include arbiter in this connection string?

When I work with sql server, I set up all my connection strings with integrated security. What is the best practise for similar in Mongo connection strings?

like image 305
amateur Avatar asked May 17 '13 17:05

amateur


People also ask

How do I connect to a MongoDB connection?

To connect to a MongoDB Server using username and password, you have to use 'username@hostname/dbname'. Where username is the username, password is the password for that user and dbname is the database to which you want to connect to. Note : You can use multiple hostname to connect to with a single command.

What is my MongoDB URI?

Find MongoDB URIClick on “Overview” tab in the menu bar. Scroll down the Overview page and you will see the MongoDB URI information.

What is SRV in MongoDB connection string?

The SRV record points to the server or servers that will comprise the members of the replica set. The TXT record defines the options for the replica set, specifically the database that will be used for authorization and the name of the replica set.


2 Answers

Is it correct not to include arbiter in this connection string?

You don't need to provide the arbiter details, it will be automatically discovered by your app-driver.

The only thing you can provide in mongoURI is SSL option or username and password for the database that you want to connect. But let me remind you, some of the driver don't honor SSL or 'username' and 'password' in mongoURI.

http://docs.mongodb.org/manual/reference/connection-string/#uri.ssl

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
like image 131
Abhishek Kumar Avatar answered Oct 19 '22 11:10

Abhishek Kumar


I'd suggest you consult the documentation. It can answer most of your questions. In addition, I see you are using the alternative connection string syntax. I'd highly suggest changing to the other connection string format as we will likely be deprecating the version you are using. The equivalent connection string would be

 mongodb://myprimary.com:27017,mysecondary.com:27017/MyDatabase/?replicaset=MySet.

Finally, you'll find documentation at the previous link regarding authentication. We don't have the "integrated security" option, but we do support SSPI integration (also called GSSAPI and kerberose). You'll find it referred to as External Authentication in our documentation. The caveat is that the MongoDB server you are running will need to be on a linux box and setup with kerberos. This can be a complicated process when used in conjunction with Active Directory to get the keytab file out.

like image 40
Craig Wilson Avatar answered Oct 19 '22 11:10

Craig Wilson