是否可以在mongodb中查询哈希索引键的散列范围? [英] Is it possible to query for a range of hashes of a hashed indexed key in mongodb?
本文介绍了是否可以在mongodb中查询哈希索引键的散列范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为mongodb集合中的键"userId"启用了基于散列的分片.是否可以获取所有散列值为"userId"介于"abcd"和"cdef"之间的文档?
I have a hashed based sharding enabled for a key "userId" in a mongodb collection. Is it possible to get all documents whose hashed values of "userId" are between, let's say, "abcd" and "cdef"?
谢谢!
推荐答案
我发现的一种方法是使用以下查询:
One way that I found is to use the following query:
db.mycollection.find({
"$and": [
{_id: {"$gt": -5012941854059245285}},
{_id : {"$lt": -4712634714892678072}}
]}).hint({_id: "hashed"})
其中长数字是_id的哈希值. 它对我有用,但这是最好的方法吗?我可以确定它将与即将发布的mongodb版本一起使用吗?
where the long numbers are hashed values of _id. It works for me, but is it the best way of doing so? Can I be sure that it will work with the upcoming releases of mongodb?
这篇关于是否可以在mongodb中查询哈希索引键的散列范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文