Adam Zerner
Adam Zerner

Reputation: 19238

Why specify the database in the mongodb connection string if you aren't authenticating?

To connect to MongoDB, you need to use http://mongodb.github.io/node-mongodb-native/2.0/api/MongoClient.html#.connect.

My question is about specifying the database in the connection string. It says:

Optional. The name of the database to authenticate if the connection string includes authentication credentials in the form of username:password@. If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database.

It seems to me that it's only useful to have the database if you also have the username:password@. But I've seen examples where the database is specified without the username:password@. The Node Driver example itself uses the string mongodb://localhost:27017/myproject.

Why would you ever want to have the database without the username:password@?

Upvotes: 0

Views: 532

Answers (1)

B3rn475
B3rn475

Reputation: 1057

All the operation you will do will be done in the database you are choosing.

If you avoid the /database component you need to force it in the code (try to avoid hard coded elements) or you will work in the default database (not a great idea)

Upvotes: 1

Related Questions