If I have a database with some sharded and unsharded collections.
Can I direct connect to the primary shard to access(include read and write) the unshard collections without any problem?
I want to do this because I think connect to mongos only decrease the performance for accessing unshard collection.
I have tried this and it works. But I’m afraid there are some issues that I don’t know here.
In general connecting via the
mongosshould not have significant performance overhead for your unsharded collections.It’s also worth noting that if your other collections are sharded, your application will not be able to take advantage of a single connection pool for both sharded and unsharded collections so you will have to manage this in your application logic.
At the moment this approach will work since the unsharded collections always live on the primary shard for the database.
However, be aware that there is work underway to distribute unsharded collections across shards (see SERVER-939 in the MongoDB Jira issue tracker). When that change happens you can no longer assume that the unsharded collections live in the primary shard, and it would be safer to rely on the
mongosto route correctly.