Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

As far as I can understand, not all databases in a MongoDB shard cluster have to be sharded; I can keep some databases unsharded, on only one of the shards.

So suppose I have a shard cluster, with shards (i.e. replica sets) rs0 and rs1. rs0 has a database foo, which is unsharded. I have no plan to shard it or move it to rs1.

Is there any harm in letting some clients connect to rs0 directly and use the foo database without going through mongos?

I have only tested that it is possible to connect directly to rs0 and make queries in foo, but I don't know if it is potentially dangerous in my use case.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Mongo will happily let you directly access any database on any individual node you hit. If that database is sharded, you can still access it but will only get results from that shard. This also means that you can have unsharded databases on a node and it'll return results from that unsharded database.

Yes, it is safe to directly access the replicaset members for that unsharded database.

It's also possible to do it through the MongoS process same as the sharded access. This may make code-paths easier, though it does add a bit of latency to the entire call.


  • Database is a feature of Nodes.
  • Sharding is a feature of Databases.
  • Replica status is a feature of Databases.
  • MongoS and Config servers represent the management layer needed to do Sharding.

A database that is not sharded does not need MongoS or Config, and can be directly accessed safely.

share|improve this answer
    
Just a caveat to this post - if you enable authentication, you only get credentials on one shard - for unsharded databases this does not matter (it is only on one shard) - but for sharded databases, if you connect directly, you will not necessarily have the same auth experience. Also, your admin database does not live on any shard, so you cannot use admin credentials when connected directly (without duping the admin users on the shard). There are also consequences around migrations and orphaned docs for sharded databses. Generally, if sharded, I would always recommend going though the mongos. –  Adam C Sep 9 '13 at 9:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.