如何使用Spring从MongoDB中嵌入数组的内部文档中检索数据?
{
"project" : "proj001",
"sourcevo" : [
{
"name" : "HpAlm",
"type" : "database",
"source" : "mysql",
"toolvo" : {
"url" : "https://123.com",
"userName" : "123user",
"password" : "password"
},
"dbvo" : {
"servername" : "",
"userName" : "",
"password" : ""
}
}
]
}
答案 0 :(得分:0)
使用MongoDB db.collection.find()
方法,下面的查询将返回 sourcevo 数组包含 name 字段等于&#34的元素的所有文档; HpAlm"
db.collection.find("{ sourcevo.name : { $eq : 'HpAlm' } }");
在MongoTemplate中,查询应如下所示:
BasicQuery myQuery = new BasicQuery("{ sourcevo.name : { $eq : 'HpAlm' } }");
List<Document> docsList = mongoOperation.find(myQuery, Document.class);