如何构建这些需求? (微服务)
How to structure these requirements? (microservices)
我有一个客户微服务(客户文件)和一个银行账户微服务(银行账户文件)。我如何构建这些要求?
有两种类型的客户:个人和企业。
一个个人客户最多只能有一个储蓄账户、一个支票账户或定期账户。
一个企业客户可能没有一个储蓄或定期账户,但可能有多个支票账户。
在客户文档中,我有一个标识银行账户的 ID 属性,可以满足第一个要求,但是,第二个表明如果是业务类型,您可以拥有多个支票账户。
---------------------
编辑:
添加了更多要求。
商业银行账户可能有一个或多个账户持有人和零个或多个授权签字人。
系统必须允许查询客户拥有的银行账户的所有动向和类型(取款或存款)。
db
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"
}
}
])
db
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")
},
{
"_id": 3,
"type": "business",
"name": "Apple2",
"createAt": ISODate("2022-01-13T05:10:42.220Z")
}
],
"accounts": [
{
"_id": 1,
"type": "saving",
"money": 12000
},
{
"_id": 2,
"type": "checking",
"money": 8000
},
{
"_id": 3,
"type": "checking",
"money": 6000
},
{
"_id": 4,
"type": "checking",
"money": 7000
}
],
"clientRoles": [
{
"_id": 1,
"client_id": 1,
"account_id": 1,
"type": "holder"
},
{
"_id": 2,
"client_id": 2,
"account_id": 3,
"type": "holder"
},
{
"_id": 3,
"client_id": 3,
"account_id": 3,
"type": "signatory"
}
],
"clientMovements": [
{
"_id": 1,
"client_id": 1,
"account_id": 1,
"type": "deposit",
"money": 20000
},
{
"_id": 2,
"client_id": 1,
"account_id": 1,
"type": "withdraw",
"money": 8000
}
]
}
汇总
db.clients.aggregate([
{
"$match": {
"_id": 1
}
},
{
"$lookup": {
"from": "clientMovements",
"localField": "_id",
"foreignField": "client_id",
"as": "movement_docs"
}
}
])
我有一个客户微服务(客户文件)和一个银行账户微服务(银行账户文件)。我如何构建这些要求?
有两种类型的客户:个人和企业。
一个个人客户最多只能有一个储蓄账户、一个支票账户或定期账户。
一个企业客户可能没有一个储蓄或定期账户,但可能有多个支票账户。
在客户文档中,我有一个标识银行账户的 ID 属性,可以满足第一个要求,但是,第二个表明如果是业务类型,您可以拥有多个支票账户。
---------------------
编辑:
添加了更多要求。
商业银行账户可能有一个或多个账户持有人和零个或多个授权签字人。
系统必须允许查询客户拥有的银行账户的所有动向和类型(取款或存款)。
db
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"
}
}
])
db
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")
},
{
"_id": 3,
"type": "business",
"name": "Apple2",
"createAt": ISODate("2022-01-13T05:10:42.220Z")
}
],
"accounts": [
{
"_id": 1,
"type": "saving",
"money": 12000
},
{
"_id": 2,
"type": "checking",
"money": 8000
},
{
"_id": 3,
"type": "checking",
"money": 6000
},
{
"_id": 4,
"type": "checking",
"money": 7000
}
],
"clientRoles": [
{
"_id": 1,
"client_id": 1,
"account_id": 1,
"type": "holder"
},
{
"_id": 2,
"client_id": 2,
"account_id": 3,
"type": "holder"
},
{
"_id": 3,
"client_id": 3,
"account_id": 3,
"type": "signatory"
}
],
"clientMovements": [
{
"_id": 1,
"client_id": 1,
"account_id": 1,
"type": "deposit",
"money": 20000
},
{
"_id": 2,
"client_id": 1,
"account_id": 1,
"type": "withdraw",
"money": 8000
}
]
}
汇总
db.clients.aggregate([
{
"$match": {
"_id": 1
}
},
{
"$lookup": {
"from": "clientMovements",
"localField": "_id",
"foreignField": "client_id",
"as": "movement_docs"
}
}
])