1- sh . removeShardTag ( "rs1" , "US" ) ;
2-
3- sh . removeShardTag ( "rs2" , "EU" ) ;
4-
5- sh . addShardTag ( "rs1" , "US" ) ;
6-
7- sh . addShardTag ( "rs2" , "EU" ) ;
8-
9- sh . disableBalancing ( "test.sample" ) ;
10-
11- db . sample . drop ( ) ;
12-
13- db . createCollection ( "sample" ) ;
14-
15- db . sample . createIndex ( { location : 1 , _id : 1 } )
16-
17- sh . addTagRange (
18- "test.sample" ,
19- { "location" : "US" , "_id" : MinKey } ,
20- { "location" : "US" , "_id" : MaxKey } ,
21- "US"
22- ) ;
23-
24- sh . addTagRange (
25- "test.sample" ,
26- { "location" : "EU" , "_id" : MinKey } ,
27- { "location" : "EU" , "_id" : MaxKey } ,
28- "EU"
29- )
30-
31-
32- sh . enableSharding ( "test" ) ;
33-
34- sh . shardCollection ( "test.sample" , { location : 1 , _id : 1 } ) ;
35-
36- sh . enableBalancing ( "test.sample" ) ;
37-
38- db . sample . insert ( {
39- "_id" : ObjectId ( "5787936b94afebe02398521a" ) ,
40- "location" : "US" ,
41- "__v" : 0
42- } ) ;
43-
44- db . sample . insert ( {
45- "_id" : ObjectId ( "5787a08c94afebe023985224" ) ,
46- "location" : "EU" ,
47- "__v" : 0
48- } ) ;
49-
50- sh . startBalancer ( ) ;
51-
1+ sh . removeShardTag ( "rs1" , "US" ) ;
2+
3+ sh . removeShardTag ( "rs2" , "EU" ) ;
4+
5+ sh . addShardTag ( "rs1" , "US" ) ;
6+
7+ sh . addShardTag ( "rs2" , "EU" ) ;
8+
9+ sh . disableBalancing ( "test.sample" ) ;
10+
11+ db . sample . drop ( ) ;
12+
13+ db . createCollection ( "sample" ) ;
14+
15+ db . sample . createIndex ( { factoryId : 1 } ) ;
16+
17+ sh . enableSharding ( "test" ) ;
18+
19+ sh . shardCollection ( "test.sample" , { location : 1 , factoryId : 1 } ) ;
20+
21+ sh . addTagRange (
22+ "test.sample" ,
23+ { "location" : "US" , "factoryId" : MinKey } ,
24+ { "location" : "US" , "factoryId" : MaxKey } ,
25+ "US"
26+ ) ;
27+
28+ sh . addTagRange (
29+ "test.sample" ,
30+ { "location" : "EU" , "factoryId" : MinKey } ,
31+ { "location" : "EU" , "factoryId" : MaxKey } ,
32+ "EU"
33+ ) ;
34+
35+
36+
37+
38+ sh . enableBalancing ( "test.sample" ) ;
39+
40+ for ( var i = 0 ; i < 100 ; i ++ ) {
41+ db . sample . insert ( {
42+ "location" : "US" ,
43+ "factoryId" : NumberInt ( i )
44+ } ) ;
45+
46+ db . sample . insert ( {
47+ "location" : "EU" ,
48+ "factoryId" : NumberInt ( 100 + i )
49+ } ) ;
50+ }
51+
52+ sh . startBalancer ( ) ;
53+
5254db . sample . find ( ) ;
0 commit comments