我是 MongoDB 新手,所以请原谅我的无知。
我有一个 mongoDB,其中包含一堆类似这样的文档
["field": "blah", "version":"1" ...]
["field": "blah", "version":"2" ...]
["field": "blah", "version":"1"....]
["field": "blah1", "version":"10"...]
["field": "blah2", "version":"100"...]
["field": "blah3", "version":"1"....]
["field": "blah3", "version":"2"....]
["field": "blah2", "version":"1"....
我正在尝试发送查询列表并批量获取所有记录。有可能这样做吗?
List<Docs> fetchDocs(Map<String, String> queries)
{
CriteriaContainer cc=null;
Query<Docs> query = this.mongoDao.createQuery(MyClass.class);
for (Map.Entry<String,String >entry : queries.entrySet())
{
if(cc ==null)
{
cc= query.criteria("Field").equal(entry.getKey()).and(query.criteria("version").equal(entry.getValue()));
}
else
{
cc.or(query.criteria("Field").equal(entry.getKey()).and(query.criteria("version").equal(entry.getValue()));)
}
}
query.and(cc);
List<Docs> doc = query.asList();
return doc;
}
我没有得到正确的列表。我不确定我是否正确编写了此查询。
本质上,我想像这样获取结果或查询
[{"Field":"blah,"version":1 } $or {"Field":"blah1", "version":10} ]
它应该返回给我一个包含
["field": "blah", "version":"1" ....]
["field": "blah1", "version":"10"....]