MongoDb 模式设计多集合 vs 一个集合

MongoDb schema desgin multi collections vs one collection

我是 NoSql 的新手,我正在做一个项目,需要将 Nodejs 与 mongodb 一起使用, 我读了很多书,但似乎无法理解 out.The 应用程序将具有具有一对多关系的类别和项目,我应该使用 1 个集合,其中类别对象具有一系列产品。 或使用 2 个集合(类别和产品)

如果类别有很多产品,并且您存储了类别products 的数组,随着 products 的数量增加 ,它很有可能变成无界数组 category,会影响数据库的整体性能。 avoid having unbounded arrays in your schema. Thus, it would be better to have 2 collections, one for category and another for products (with a field called categoryId). You can read more about the best practices around modelling One-to-Many relationships here.

总是更好的主意