[英]How should I structure my API or Schema based on certain requirements
[英]How to structure these requirements? (microservices)
我有一個客戶微服務(客戶文件)和一個銀行賬戶微服務(銀行賬戶文件)。 我如何構建這些需求?
有兩種類型的客戶:個人和企業。
個人客戶最多只能擁有一個儲蓄戶口、一個支票戶口或定期戶口。
商業客戶可能沒有一個儲蓄或定期賬戶,但可能有多個支票賬戶。
在客戶文檔中,我有一個標識銀行帳戶的 ID 屬性,並且可以滿足第一個要求,但是,第二個表明如果它是一種業務類型,您可以擁有多個支票帳戶。
D b
db={
"clients": [
{
"_id": 1,
"type": "personal",
"name": "Tom",
"createAt": ISODate("2022-01-10T11:23:25.184Z")
},
{
"_id": 2,
"type": "business",
"name": "Apple",
"createAt": ISODate("2022-01-12T05:10:42.220Z")
}
],
"accounts": [
{
"_id": 1,
"client_id": 1,
"type": "saving",
"money": 12000
},
{
"_id": 2,
"client_id": 1,
"type": "checking",
"money": 8000
},
{
"_id": 3,
"client_id": 2,
"type": "checking",
"money": 6000
},
{
"_id": 4,
"client_id": 2,
"type": "checking",
"money": 7000
}
]
}
總計的
db.clients.aggregate([
{
"$lookup": {
"from": "accounts",
"localField": "_id",
"foreignField": "client_id",
"as": "account_docs"
}
}
])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.