Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 636 Bytes

File metadata and controls

17 lines (13 loc) · 636 Bytes

Mongo data center aware ObjectId

This is just an idea on MongoDB ObjectId

If you want to split data on multiple shards using only the _id field

sh.enableSharding("demo");
sh.shardCollection("demo.foo", { _id : 1 } );
sh.addTagRange("demo.foo", { _id: MinKey }, { _id: ObjectId("640000000000000000000000") }, "DC1");
sh.addTagRange("demo.foo", { _id: ObjectId("640000000000000000000000") }, { _id: MaxKey }, "DC2");

When the app starts you have to set the right value for the data-center identifier to target data to desired data-center using only the _id field

DataCenterAwareIdGenerator.DataCenter = 200;