Mongoose: populate() / DBref or data duplication?

后端 未结 2 349
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 07:55

I have two collections:

  1. Users
  2. Uploads


Each upload has a User associated with it and I need to know their

2条回答
  •  孤街浪徒
    2021-02-01 08:45

    Populate() is just a query. So the overhead is whatever the query is, which is a find() on your model. Also, best practice for MongoDB is to embed what you can. It will result in a faster query. It sounds like you'd be duplicating a ton of data though, which puts relations(linking) at a good spot.

    "Linking" is just putting an ObjectId in a field from another model.

    Here is the Mongo Best Practices http://www.mongodb.org/display/DOCS/Schema+Design#SchemaDesign-SummaryofBestPractices

    Linking/DBRefs http://www.mongodb.org/display/DOCS/Database+References#DatabaseReferences-SimpleDirect%2FManualLinking

提交回复
热议问题