Mongo DB: dividing slice with minimum / maximum hashed key as lower / upper bounds

This might be a dumb question with an obvious answer, but how do I split a piece with a minimum / maximum hashed key as a lower / upper bound?

For example, I have this piece that I want to split:

{ "_id" : "database-name.collectionName-_id_5232174760913548110", "lastmod" : Timestamp(5, 1), "lastmodEpoch" : ObjectId("5474796988a23861ead5dc60"), "ns" : "database-name.collectionName", "min" : { "_id" : NumberLong("5232174760913548110") }, "max" : { "_id" : { "$maxKey" : 1 } }, "shard" : "dimA" } 

I tried to split it:

 db.adminCommand( { split: "database-name.collectionName", bounds: [{_id: NumberLong("5232174760913548110")}, {{_id: {"$maxKey" : 1}}}] } ) 

but failed with the error message "no chunk found from given upper and lower bounds".

The command works for pieces that do not have a maximum / minimum key, so I think I should not use {_id: {"$maxKey" : 1}} as the upper bound.

Any idea?

Thanks,

Nina.

+1
source share
1 answer

Basically this is about how $maxKey displayed compared to how you pass it to the shell to use it in a command. The simplest thing is to show a working example, so here is my original layout of my test collection ( foo.bar ):

 foo.bar shard key: { "_id" : "hashed" } chunks: shard0000 3 { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("-4097713469691957209") } on : shard0000 Timestamp(1, 3) { "_id" : NumberLong("-4097713469691957209") } -->> { "_id" : NumberLong("1468066378930898747") } on : shard0000 Timestamp(1, 4) { "_id" : NumberLong("1468066378930898747") } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 2) 

To break this last fragment, do the following:

 db.adminCommand( { split: "foo.bar", bounds: [{_id: NumberLong("1468066378930898747")}, {_id: MaxKey}] } ) { "ok" : 1 } 

Now, to prove this, the layout looks like this:

 foo.bar shard key: { "_id" : "hashed" } chunks: shard0000 4 { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("-4097713469691957209") } on : shard0000 Timestamp(1, 3) { "_id" : NumberLong("-4097713469691957209") } -->> { "_id" : NumberLong("1468066378930898747") } on : shard0000 Timestamp(1, 4) { "_id" : NumberLong("1468066378930898747") } -->> { "_id" : NumberLong("5350365356528563634") } on : shard0000 Timestamp(1, 5) { "_id" : NumberLong("5350365356528563634") } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 6) 
+1
source

Source: https://habr.com/ru/post/989009/


All Articles