1

If we add any new data/collection to the existing(running) shard cluster. Is there any way that the data/collection gets sharded automatically.
If yes, How to achieve that?.

2
  • Are you adding data to sharded collection or a new collection? Jul 22, 2017 at 22:50
  • @SqlWorldWide I am adding a new collection to the database. Jul 24, 2017 at 4:04

2 Answers 2

2

No it is not possible to automatically shard the collection. This is what you have to do per collection.

Ref:

You will need to run shardCollection command in order to shard a new collection. The collection must have an index whose prefix is the shard key. The following operation enables sharding for the people collection in the records database and uses the zipcode field as the shard key:

use admin
db.runCommand( { shardCollection: "records.people", key: { zipcode: 1 } } )

Shards a collection to distribute its documents across shards. You must run enableSharding on a database before running the shardCollection command. The shardCollection command must be run against the admin database.

A database can have a mixture of sharded and unsharded collections. Sharded collections are partitioned and distributed across the shards in the cluster. Unsharded collections are stored on a primary shard. Each database has its own primary shard.

1
  • the question was "Is there any way that the data/collection gets sharded automatically." and answer to that is no. It's not possible.
    – JJussi
    Jul 25, 2017 at 9:27
0

You mean, when you create new collection to sharded database.

Answer is simple. NO! Every DB and collection in them, must be shard individually. Just because all collections are not created as equal and earlier used sharding key is not best solution to everything (every collection).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.