我正在构建一个API以从mongodb中检索文档,mongo有超过3000万个文档,使用下面的Java代码以这种结构查询文档大约需要45-60秒:
{
"Type": "CUS",
"ID": "01010101",
"Set": [
{
"Group": "Marketing",
"Rule": "Rule_1",
"Ind": "Y",
},
{
"GroupName": "Sales",
"RuleName": "Rule_2",
"Ind": "N",
}
]
}
BasicDBObject query = new BasicDBObject();
query.put("ID", new BasicDBObject("$in", payload.getIds()));
FindIterable<Document> documents = collection.find(query);
for (Document doc : documents) {
// looping through docs and then construct some objects and returns the result to the controller class
}
循环部分“ for(Document doc:documents)”似乎花费了很多时间,我不确定发生了什么,请您帮忙。
谢谢,谢谢。