假设我有一个 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 帮助我使用此查询的正确语法吗?