[英]how to retrieve data nested in two collections from firebase with angular
[英]How to get data from two collections in spring using Mongotemplate or MongoRepository
幾個月前,我開始使用spring和mongodb。 到現在為止,我還不知道如何使用Mongotemplate或MongoRepository從多個集合中獲取數據。 我有兩個集合Person和Contacts.now,現在我想獲取客戶列表以及Contacts。 客戶的ID為_id,聯系人的ID為customerId,因此我如何獲取數據的客戶聯系詳細信息。
MongoDB認為,您的數據需要去規范化。 您需要與相應的“聯系人”一起存儲“人員/客戶”數據。 這是一種1:n的關聯。 您可以在以下模式中輕松存儲所需的數據,以下是一個示例“人/客戶”文檔,該文檔嵌入了他的“聯系”詳細信息=>
{
name:"abc",
age: 35,
Contact:{[email:"abc1@gmail.com",mobile:123],[email:"abc2@gmail.com",mobile:234]}
}
如果最終像上面提到的那樣對數據進行規范化,則傾向於放棄MongoDB提供的強大的嵌入功能,並最終在代碼中進行聯接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.