我已存儲的一些數據作爲彈簧mongodb的查找文件如果單個場在列表
{
"_id" : ObjectId("abc"),
"_class" : "com.xxx.Team",
"name" : "Team 1",
"members" : [
{"userId" : 1, "email" : "[email protected]" },
{"userId" : 2, "email" : "[email protected]" },
]
}
{
"_id" : ObjectId("xyz"),
"_class" : "com.xxx.Team",
"name" : "Team 2",
"members" : [
{"userId" : 2, "email" : "[email protected]" },
{"userId" : 3, "email" : "[email protected]" }
]
}
我有2 POJO類Team
(映射到整個文檔)的文檔內相匹配,TeamMember
(映射到members
內部一個文件)。
現在我想找到特定用戶屬於哪個團隊。例如,如果我搜索[email protected]
它應該返回我的文檔團隊1。同樣搜索[email protected]
應將它們都作爲它們在兩個文檔中返回。
由於我對春天很陌生,無法找出如何解決這個問題。
注:我使用MongoTemplate
?更新您的問題與您的pojo類(團隊和團隊成員) – pvpkiran
@pvpkiran我正在使用MongoTemplate – BiJ