Mongodb – Detailed behaviour of mongos in context of sharded Mongo cluster

mongodbmongodb-3.4sharding

I have a mongo cluster as follows:

  1. 3 shards, located in the 3 main global regions (APAC/EMEA/AMER)
  2. The shardKey is "Region".
  3. Each region has a mongos running locally, "close" to its users, "close" to its mongods.

Question: when the mongos receives an insert request for a document who's region is not the mongos "close" region, does the mongos:

a) route the insert into its "close" regional shard then let the balancer sort out moving the document to its correct shard.
OR
b) route the insert to the correct regional shard directly.

It seems to me that a) would give faster inserts than b) but takes longer for the database to settle down to its eventual state.

Which one is what mongos actually does?

Thanks!

Best Answer

It does the second option 'route the insert to the correct regional shard directly`.

See this answer for details.

Where to insert data after sharding?

More resource:

https://docs.mongodb.com/manual/core/sharded-cluster-query-router/