In MongoDB, can hashed shard keys improve query isolation on range queries?

StackOverflow https://stackoverflow.com/questions/19701868

  •  02-07-2022
  •  | 
  •  

سؤال

In Mongo docs, it says that

MongoDB automatically computes the hashes when resolving queries using hashed indexes. Applications do not need to compute hashes.

From here: http://docs.mongodb.org/manual/tutorial/choose-a-shard-key/

My common sense tells me that this can only be valid for EQUALS queries. Is this also valid for range queries? As hashing does not maintain order, I suppose not.

Example: Say I have a hashed shard key on field k. Definitely, it can help isolate a query like {k : 111}. Can it also help isolate a query like {k : {'$gt' : 111}} ?

Thanks in advance.

هل كانت مفيدة؟

المحلول

From the 3rd paragraph here: http://docs.mongodb.org/manual/core/index-hashed/

Hashed indexes do not support range queries.

Sorry - it can be frustrating, for sure.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top