简体   繁体   English

如何构建这些需求? (微服务)

[英]How to structure these requirements? (microservices)

I have a customer microservice (customer document) and a bank account microservice (bank account document).我有一个客户微服务(客户文件)和一个银行账户微服务(银行账户文件)。 How do I structure these requirements?我如何构建这些需求?

There are two types of clients: personal and business.有两种类型的客户:个人和企业。

  • A personal client can only have a maximum of one savings account, one checking account or fixed term accounts.个人客户最多只能拥有一个储蓄户口、一个支票户口或定期户口。

  • A business client may not have one savings or fixed-term account but may have multiple checking accounts.商业客户可能没有一个储蓄或定期账户,但可能有多个支票账户。

In the customers document I have an ID attribute that identifies the bank account and that could fulfill the first requirement, however, the second one indicates that you can have multiple checking accounts if it is a business type.在客户文档中,我有一个标识银行帐户的 ID 属性,并且可以满足第一个要求,但是,第二个表明如果它是一种业务类型,您可以拥有多个支票帐户。

db 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
    }
  ]
}

aggregate总计的

db.clients.aggregate([
  {
    "$lookup": {
      "from": "accounts",
      "localField": "_id",
      "foreignField": "client_id",
      "as": "account_docs"
    }
  }
])

mongoplayground mongoplayground

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该如何根据某些要求构建我的 API 或 Schema - How should I structure my API or Schema based on certain requirements XPath的MySql与MongoDB一致的MySql对异常的结构要求 - MySql with XPath versus MySql in unison with MongoDB for unusual structure requirements 如何部署对 Kube.netes 有 MongoDB 依赖的微服务? - How to deploy Microservices with MongoDB dependency on Kubernetes? 如何理解mongoDB Api方法要求? - how to understand mongoDB Api method requirements? 您应该如何处理微服务中的身份验证和共享用户信息? - How should you deal with auth and sharing Users info across microservices? JHipster - 如何在微服务架构中仅在 Eclipse 中调试一个网关(或微服务)? - JHipster - How to debug in Eclipse only one gateway (or microservice) in a microservices architecture? 如何使用共享数据库在 Graphql 微服务之间获取数据? - How to get data between Graphql Microservices with Shared Database? mongodb如何树结构? - How tree structure with mongodb? 使用 mongodb 作为数据库的微服务部署的主节点和工作节点需要多少 CPU 和 RAM? - how much cpu and RAM is necessary for master and worker node for a microservices deployment with mongodb as database? 微服务中的数据库访问复制 - Database Access Replication in Microservices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM