MongoDB query on all sharded collections without shardkey

廉价感情. 提交于 2019-12-02 15:39:42

问题


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

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

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.

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

What is the right approach?

Thanks in advance


回答1:


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.



来源:https://stackoverflow.com/questions/23785380/mongodb-query-on-all-sharded-collections-without-shardkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!