0
votes

Sorry, I couldn't come up with a better title for this. The situation:

We have a two replica sets (rs0, rs1) each with 3 members, acting as shards in a sharded cluster. (Along with 3 config servers, and mongos instances running on our app servers).

Currently we are not using rs1, as we haven't reached a point where we need to shard the dbs yet (the replica sets are running on virtual servers, with rs1 set to mimimal specs).

Recently we added a new DB via a console connected to mongos. I assumed that this DB would be created on rs0, but in fact it was created on rs1. So this has left a few questions in my mind:

  • What rules govern which shard(replica-set) a new (non-sharded) DB will be created on, when created from a mongos instance?
  • Is this currently a valid configuration? (I.e. non-sharded dbs on different shards).
  • What is the best way to move the new db from rs1 back to rs0?

Thank you!

1

1 Answers

1
votes

In a sharded cluster, a database can be sharded or unsharded, but either way, it is assigned a primary shard at creation. Unsharded collections in the database are stored on the primary shard. It's normal that the choice of primary shard will be different for different databases. The best way to move the database is to use the movePrimary command. Of course, exercise caution when shuffling data; in particular, make sure you drain sharded collections out of the database first using removeShard. The docs have proper advice for the migration.