【发布时间】:2015-03-28 12:52:48
【问题描述】:
假设我有一个如下的 mongo 集合:
/* 0 */
{
"_id" : {
"index" : "index1",
"version" : 1
}
}
/* 1 */
{
"_id" : {
"index" : "index2",
"version" : 2
}
}
/* 2 */
{
"_id" : {
"index" : "index1",
"version" : 3
}
}
我想使用 Spring 的 mongoTemplate 编写一个查询来仅检索那些具有 _id.index = index1 的文档。
使用 mongo shell 我可以编写如下查询:
db.collectionName.find({"_id.index" : "index1"})
但是,我认为使用 mongoTemplate 的方法不起作用。我试过了:
Query query = new Query();
query.addCriteria(Criteria.where("_id.index").is("index1"));
mongoTemplate.find(query, SomeJavaObject.class, COLLECTION_NAME);
谁能帮助我使用 mongoTemplate 使用此查询的正确语法?
【问题讨论】:
标签: mongodb spring-data mongotemplate