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?
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.
Find MongoDB URIClick on “Overview” tab in the menu bar. Scroll down the Overview page and you will see the MongoDB URI information.
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.
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]]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With