0

I am looking at modelling some data in MongoDB. Say for example a product has a supplier , and I want to embed the supplier name in the product

{
    sku: 'prd1',
    name: 'Product one',
    supplier: {
        supplierId: '5a37112f70467f45ec871e5b'
        code: 'sup01',
        name: 'Supplier One'
    }
}

supplierId = the object id of the record in the supplier collection.

The supplier name would very rarely , if ever be updated. But if it does update , I need to be able to update all the embedded names in where that supplier is in a product.

I'm not overly familiar with Firebase , but it seems ( Reading This Blog Post ) that there is a mechamism called "multi-path updates" which solves this problem. Is there something similar in MongoDB , or do I need to manually keep track of all places the data exists and write my own code to update it?

Martin Thompson
  • 3,415
  • 10
  • 38
  • 62
  • Ah! You read the first article you found that matched the words that came in to describe your problem. However that is not actually what that "firebase feature" is about. They are talking about updating objects with "varying key name structures", and that is something MongoDB definitely does not do. But if has nothing to do with "keeping relations", despite the wording of the article title matching your own expected explanation of your situation. – Neil Lunn Nov 14 '18 at 22:05
  • Bottom line here is that if you are expecting something to "manage" where you have `"sup01"` and you want to change the attached name to `"Supplier Uno"`, then that is a product of "relational design". The trade-off with MongoDB is that "repeating that name" everywhere as you have is **faster** than going and looking it up from another source. The other side of that *trade-off** is of course the speed comes at the cost of **storage** and **maintenance**. So in essence **it's up to you to manage yourself**. – Neil Lunn Nov 14 '18 at 22:08

0 Answers0