Mongodb – Is there way to have logical connection in MongoDB

mongodb

For example in oracle we can define tns.ora so client can connect with logical name. Although mongos can run on client servers, but when there are many different partner applications we we will need to worry about running daemon on partner machines. Is there alternative to provide mongo connection in a logical way and not necessarily physical mongo sever and port number? Thanks!

Best Answer

If your client applications are connecting directly to MongoDB, they will typically use a connection string which varies depending on the type of deployment:

  • Standalone - mongod hostname (and optionally, port)
  • Replica set - includes one or more mongod hosts in the replica set as a "seed list" to discover the current configuration
  • Sharded cluster - includes one or more mongos hosts to connect to the sharded cluster

There isn't a direct equivalent of the "logical connection" abstraction. However, since you are already connecting via mongos, it sounds like you have a sharded cluster which does abstract the connection details for the underlying shards. All mongos connecting to the same cluster have to use the same --configdb list.

If you deploy a mongos per application host, each application can connect to the mongos on localhost. Alternatively you could have a fixed set of shared mongos and expose these via DNS cnames that resolve to "local" mongos for that application or data centre.

If you want to further lockdown per-client access, each client application could authenticate using different credentials which limit their access/permissions per-database. MongoDB 2.6 adds further granularity including collection-level access. For more information see Security Concepts in the MongoDB manual.