Mercury Trivival
Mercury Trivival

Reputation: 11

Insert data to Mongob Shard Cluster?

At first below is my shard cluster I create by Ops Manager:

I have 2 Mongos and 2 Shard (each shard configure replicates set). I not configure any shard key, I mean not sharded collections esxit in my cluster.

When I use mongos to insert a database for testing purposes, the database store only one Shard.

So I want when I insert a database, data can split and store balance on both shards. And I can query from mongos to get accurate data.

Anyone have the same issue?

Upvotes: 1

Views: 2081

Answers (2)

Stennie
Stennie

Reputation: 65333

Databases and collections are not sharded automatically: a sharded deployment can contain both unsharded and sharded data. Unsharded collections will be created on the primary shard for a given database.

If you want to shard a collection you need to take a few steps in the mongo shell connected to a mongos process for your sharded deployment:

See Shard a Collection in the MongoDB manual for specific steps.

It is important to choose a good shard key for your data distribution and use case. Poor choices of shard key may result in unequal data distribution or limit your sharding performance. The MongoDB documentation has more information on the considerations and options for choosing a shard key.

If you are not sure a collection if a collection sharded or want to see a summary of the current data distribution, you can use db.collection.getShardDistribution() in the mongo shell.

Upvotes: 1

Korteby Farouk
Korteby Farouk

Reputation: 649

You need to implement Zone Range so according the range the data will be stored for each shred.

The code bellows helps you to create zones :

For the zone01 :

sh.addShardTag("rs1", "zone01")
sh.addTagRange("myDB.col01", { num: 1 }, { num: 10 }, "zone01")

For the zone02 :

sh.addShardTag("rs2", "zone02")
sh.addTagRange("myDB.col01", { num: 11 }, { num: 20 }, "zone02")

This will help you Manage Shard Zones

Upvotes: 0

Related Questions