猫鼬模型关系

时间:2021-03-31 12:38:46

标签: node.js database mongodb mongoose nosql

我正在为 mongoose 数据库建模,需要解决一些问题。这是我们的业务规则和模型架构:

  • 用户通过注册表进行注册
  • 网关包含所有可用的网关(用于防止重复)
  • 每个用户都可以与多个网关相关联并具有特定的 每个网关的配置,如活动/非活动、api 密钥、支付 方法(GatewayInfo 架构)。
  • 当用户使用当前用户/网关配置启用/禁用网关时,网关会集成到电子商务商店中
    const userSchema = new Schema(
      {
        email: { type: String, required: true, unique: true},
        password: {type: String, required: true}
      }
    
    const gatewaySchema = new Schema(
      {
        idGateway: { type: String, unique: true },
        name: String,
      }
    
    const gatewayInfoSchema = new Schema(
      {
        user: { type: Schema.Types.ObjectId, ref: 'User' },
        gateway: { type: Schema.Types.ObjectId, ref: 'Gateway' },
        active: Boolean, 
        keys: { pub: String, priv: String },
        methods: [{
            method: String,
            active: Boolean
        }]
      }

      // user - gateway combination is unique 

问题是:

  1. 如何获取所有网关并获取当前用户的当前状态?
  2. 是否应该在创建网关时自动创建 GateInfo 模型(状态为 active=false)?
  3. 将架构命名为 GatewayInfo 是否有效?有什么建议吗?

感谢您的帮助。

0 个答案:

没有答案