Mongoose nested schema vs nested models

前端 未结 1 1962
长发绾君心
长发绾君心 2021-02-05 12:33

What is the difference between nesting schema in schema (subdocuments) vs creating two separate models and referring to them, What about their performance?

subdo

相关标签:
1条回答
  • 2021-02-05 13:11

    When using subdocuments, you actually have a copy of the data within your parent-document, wich allows you to get all the document + sub-document-data in a single query.

    When using "nested models" you're not really nesting them, but referencing from the parent-model to the child-model. In this case you have to use population, which means you can't get all the data in a single query.

    In short: subdocuments actually nest the data, and your "nested models" only reference them via their id

    0 讨论(0)
提交回复
热议问题