次のような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 シェルを使用すると、このクエリを次のように記述できます。
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 を使用して、このクエリの正しい構文を教えてください。