【问题标题】:When updating collection document in mongo, update it in every other document or collection where it is used在 mongo 中更新集合文档时,在使用它的每个其他文档或集合中更新它
【发布时间】:2021-04-19 14:20:48
【问题描述】:

我对 noSQL 数据库很陌生,并且遇到了一个我不知道如何解决的问题。 我有两个集合服务和产品。

Service 的架构如下:

    name: { type: String, required: 'Enter name' },
    price: { type: Number, required: 'Enter price' },
    description: { type: String},
    duration: { type: String, required: 'Enter duration' },
    products: {type: [Product]}

Product 的架构如下:

    name: { type: String, required: 'Enter name' },
    description: { type: String},
    qty: { type: Number, required: 'Enter quantity' },
    unitsOfMeasure: { type: String, default: UOM.Piece},
    qtyPerService: {type: Number}

现在您可以看到 Service 包含一组产品。当我更新我的产品集合中的某些产品时,它不会在包含该确切产品的服务中更新。我知道这不是因为服务产品没有链接到 Products 集合中的源文档,但我不知道如何实现这一点。

感谢任何提示或想法。 谢谢

【问题讨论】:

    标签: mongodb mongoose nosql


    【解决方案1】:

    您可以使用猫鼬的refPopulate,因为它非常舒适并且满足您的需求,请查看documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多