0

I have a development environment with two shards, one configuration server and one router as illustrated below. I have a sharded database "mydb2" and a sharded colleciton "mycollection2". When I insert data to mycollection2 from router, it is inserting to s1. And next time s2. And s1 again and so on. How can I insert data to both two shards same time. I am using MongoDb 4.2.3

enter image description here

UPDATE: I added s1 and s2 to the same zone. I declared a shard key range. But nothing changed. I insert data to the collection with ranged shard key, bu data is not distributed.

  • 2
    What do you mean by "How can I insert data to both two shards same time."? The data is written to either of the shards based upon the shard key value. It is correct that if you insert a document into to the sharded collection, it will write to only one shard. See the image from Ranged shard key document. – prasad_ Feb 10 at 14:15
  • 2
    "How can I insert data to both two shards same time.": When multiple client applications insert documents with varied shard key values, then it is likely that documents will be inserted on both shards at the same time. – prasad_ Feb 10 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.