Skip to content

Instantly share code, notes, and snippets.

@FrancescaK
Last active December 30, 2015 23:29
Show Gist options
  • Save FrancescaK/7901452 to your computer and use it in GitHub Desktop.
Save FrancescaK/7901452 to your computer and use it in GitHub Desktop.
Adding Shards and a shard key to the archive and recent clusters
#add two shards
sh.addShardTag ("shard0000", "archive")
sh.addShardTag ("shard0001", "recent")
#shard database and collection, use "_id" as shard key
sh.enableSharding("mydb")
sh.shardCollection("mydb.mydata", { "_id" : 1 })
#define tag ranges
#first tag range: from the beginning of time until 1 Jan 2013, everything goes to "archive"
sh.addTagRange("mydb.mydata", { "_id" : MinKey }, { "_id" : 201301010000032543 }, "archive")
#second tag range: from 1 Jan 2013 until the end of time (now), everything goes to "recent"
sh.addTagRange("mydb.mydata", { "_id" : 201208140000000000 }, { "_id" : MaxKey }, "recent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment