查询一千万个mongodb文档 [英] querying on 10 million mongodb documents

查看:175
本文介绍了查询一千万个mongodb文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在mongodb文档中存储书籍元数据,例如名称,作者,价格,出版商等.我有大约一千万个这样的文件,它们全都在一个集合中. 平均文档大小为1.9 KB .现在我在nameauthorsprice上都有索引.实际上,我有两个价格指数,一个是升序,另一个是降序..我的mongodb版本是2.2.0,我正在使用php驱动程序查询mongo.驱动程序的版本是1.12.但是,当我对价格进行范围查询时,会得到MongoCursorTimeoutException.在我的查询中,我正在尝试查找某个价格范围内的书,例如价格低于1000且高于500".

I am storing book meta-data like name,authors,price,publisher,etc in a mongodb document. I have about 10 million of these documents and they all are in one collection. The average document size is 1.9 KB. Now i have indexes on name,authors and price. In fact i have 2 indexes on price one in ascending order and one descending order. My mongodb version is 2.2.0 and i am using the php driver to query mongo. The driver's version is 1.12. But when i do a range query on price i get a MongoCursorTimeoutException. In my query i am trying to find books in a certain price range like "price less than 1000 and more than 500".

增加超时时间似乎不是一个好主意(已经30秒了).还有什么我可以做的以加快查询过程.

Increasing the timeout doesn't seem to be a good idea(It is already 30 sec). Is there anything else that i can do to speed up the query process.

编辑 实际上,我的价格指数是复合的.我有一个具有整数值的状态字段,所以我的价格指数看起来像{price:-1,status:1}{price:1,status:1} 另外,我正在尝试使用PHP一次检索20个文档.

EDIT Actually my price index is compound. I have a status field which has an integer value so my price index looks like {price:-1,status:1} and {price:1,status:1} Also I am trying to retrieve 20 documents at a time with PHP.

推荐答案

正如@JohnyHK所说,我的RAM太低了.因此将其增加到12 GB,现在可以使用.谢谢大家的评论和回答

As @JohnyHK said my RAM was too low. So increased it to 12 GB and it works now. Thanks everyone for their comments and answers

这篇关于查询一千万个mongodb文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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