nosql - Writing on multiple shards in mongodb -
generally, if query spreads across multiple shards, considered less optimized. takes more time reading single shard.
does hold true writing well? if writing data , distribute among multiple shards, considered less optimized?
if yes, best way write batch should go different shard?
it depends on operations, see https://docs.mongodb.com/manual/core/sharded-cluster-query-router/#sharding-mongos-targeted.
all insertone() operations target 1 shard. each document in insertmany() array targets single shard, there no guarantee documents in array insert single shard.
all updateone(), replaceone() , deleteone() operations must include shard key or _id in query document. mongodb returns error if these methods used without shard key or _id.
depending on distribution of data in cluster , selectivity of query, mongos may still perform broadcast operation fulfill these queries.
Comments
Post a Comment