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.

1 Answer 1


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.

  • 1
    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, 2013 at 9:16
  • Hi! Is this answer still up to date? would there be any problem with newer versions of mongo 3.4+? Aug 19, 2019 at 16:43
  • 1
    @xocasdashdash No idea, I haven't used mongo since 2014. Aug 20, 2019 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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