简体   繁体   English

如何在MongoDB中存储多对多关系

[英]How to store many-to-many relationships in MongoDB

I think its fair to say I'm pretty new to MongoDB having just installed the database this afternoon. 我认为可以说我对今天下午刚安装数据库的MongoDB感到陌生。

I'm managing to get to grips with storing and retrieving objects but am struggling to find the best way of storing objects that have a many-to-many relationship. 我正在设法处理对象的存储和检索,但是正在努力寻找存储具有多对多关系的对象的最佳方法。

I've already come accross the DBRef object and have got that working but this seems to only support a lazy loaded approach. 我已经遇到过DBRef对象,并且可以正常工作,但这似乎仅支持惰性加载方法。

Is there a way to encourage MongoDB to eagerly load DBRefs? 有没有办法鼓励MongoDB急于加载DBRef?
Is there a better/different way to store the many-to-many relationship? 有没有更好/不同的方法来存储多对多关系?

Many thanks 非常感谢

Rob

So first, I think you need to look at this question over here , which talks about many-to-many relationships. 所以首先,我认为您需要在这里研究这个问题 ,该问题涉及多对多关系。

The other thing to understand is the nature of "DBRefs". 要理解的另一件事是“ DBRefs”的性质。 The MongoDB database does not provide any join functionality . MongoDB数据库不提供任何联接功能

The DBRef is just a standard that several library / driver implementers agreed upon a couple of years ago. DBRef只是几年前几个库/驱动程序实现者所同意的标准。 The DBRef is just a JSON object in a specific notation that provides a pointer to some other document in some collection. DBRef只是特定表示法中的JSON对象,它提供指向某个集合中其他文档的指针。 So the implementation of "lazy vs. eager" loading is completely specific to the driver / wrapper library that you are using. 因此,“延迟与渴望”加载的实现完全特定于您使用的驱动程序/包装器库。

That stated, the concept of "eager loading" is rather pointless with MongoDB. 也就是说,MongoDB的“紧急加载”概念毫无意义。 In SQL you can potentially save on total queries by using some form of eager loading and doing a join "in advance". 在SQL中,您可以通过使用某种形式的紧急加载并“提前”进行联接来节省总查询量。 Again, the DB does not support joins, so "eager loading" takes the same number of queries as "lazy loading". 同样,数据库不支持联接,因此“紧急加载”接受的查询数量与“延迟加载”相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在MongoDB中建模多对多关系(对于MySQL用户) - How to model many-to-many relationships in MongoDB (for a MySQL user) 了解MongoDB中的多对多关系以及如何取消引用集合 - Understanding Many-to-Many relationships in MongoDB and how to dereference collections 在MongoDB中建模多对多关系 - Modelling many-to-many relationships in MongoDB 重新思考MongoDB的关系多对多关系 - Rethinking relational many-to-many relationships for MongoDB 流星CRUD多对多关系MongoDB - Meteor CRUD many-to-many relationships MongoDB CouchDB或MongoDB中的多对多关系 - Many-to-many relationships in CouchDB or MongoDB 如何在猫鼬中建立多对多关系? - how to structure many-to-many relationships in mongoose? 在 MongoDB 中设计多对多关系(而不是关系表) - Designing Many-to-Many relationships in MongoDB (instead of relational tables) 如何在不使用中间表的情况下在MongoDB中建模多对多关系? - How do you model many-to-many relationships in MongoDB without using an intermediate table? 您如何为 mongodb 数据库播种,以便 Keystone 5 CMS 识别多对多关系? - How do you seed a mongodb database such that the Keystone 5 CMS recognizes the many-to-many relationships?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM