[英]MongoDB search big data collection
I am trying search through big data collection of objects (1 000 000 000 elements). 我正在尝试搜索对象的大数据集合(1 000000000个元素)。 Sample element looks like this:
示例元素如下所示:
Document{{_id=588e6f317367651f34a06c2c, busId=34, time=1262305558050, createdDate=Sun Jan 29 23:39:42 CET 2017}}
there are busIds from 0 to 300 and time increment about 30 milisecond on each record begins from 从0到300之间有busIds,并且每条记录的时间增量大约从30毫秒开始于
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); long startDate = sdf.parse("2010.01.01 00:00:00").getTime();
Now I am looking for all data with this query: 现在,我正在使用此查询查找所有数据:
BasicDBObject gtQuery = new BasicDBObject();
List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
obj.add(new BasicDBObject("busId", vehicleId));
obj.add(new BasicDBObject("time", new BasicDBObject("$gt", startDate.getTime()).append("$lt", endDate.getTime())));
gtQuery.put("$and", obj);
System.out.println(gtQuery.toString());
FindIterable<Document> curs = collection.find(gtQuery);
gtQuery output: gtQuery输出:
{ "$and" : [ { "busId" : "34"} , { "time" : { "$gt" : 1262304705000 , "$lt" : 1262308305000}}]}
Query is working but in this way it iterates over whole 1 000 000 000 elements in collection. 查询正在工作,但是以此方式遍历集合中的整个1000000000000元素。 Is there any way to do it faster?
有什么办法可以更快地做到这一点?
尝试按照@ares的建议在busId和时间上创建复合索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.