在没有分片键的所有分片集合上进行MongoDB查询 [英] MongoDB query on all sharded collections without shardkey

查看:76
本文介绍了在没有分片键的所有分片集合上进行MongoDB查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个分片(集合)集合. 集合是用户请求.而分片键是用户ID.

I have several shard-(ed) collections. The collection is user requests. and the shard key is User Id.

我有一个名为执行时间"的字段 我想在一段时间内(lte和gte)查询所有请求.

I have a field named "Execution Time" and I want query all the requests in a period of time (lte and gte).

索引是带有分片键的,但是我的查询却没有. 我不想使用"in"运算符将所有分片键放在查询中,因为我有1000个分片键(用户). 另外,我需要在每次查询中获取所有用户ID-这意味着每次2次查询,而不是1次.

The index is with the shard key, but my query is without. I would like not to put all the shard Key in query with a "in" operator because I have a 1000 shard keys (users).. futher more to do that i need to get all user ids on every query - it means 2 queries each time instead of 1.

但是我仍然想使用索引. 添加userId> 0<的选项是什么要查询的maxUserId吗?

But still i want to use an index.. what option is to add userId > 0 < maxUserId to the query?

什么是正确的方法?

预先感谢

推荐答案

为获得理想的性能,应该以路由器(mongos)可以告诉哪个碎片包含最常见查询数据的方式选择碎片密钥.仅当find-query具有也是分片键的条件时,这才可能.

For ideal performance, shard keys should be chosen in a way the router (mongos) can tell which shard will have the data for the most common queries. This is only possible when the find-query has a criteria which is also the shard-key.

但是在这种情况下,路由器无法分辨哪个分片具有查询数据.每个分片都有相关结果的可能性不大.在那种情况下,查询需要转发到所有分片,分片将同时处理它.但是,当您有适当的索引时,这将有助于他们这样做.

But in this case it is impossible for the router to tell which shard has the data for the query. It is not unlikely that there are relevant results on every shard. In that case the query needs to be forwarded to all shards, which will process it simultaneously. But when you have an appropriate index, this will help them doing so.

这篇关于在没有分片键的所有分片集合上进行MongoDB查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆