简体   繁体   English

流星CRUD多对多关系MongoDB

[英]Meteor CRUD many-to-many relationships MongoDB

I have 3 collections interconnected through many-to-many relationships. 我有3个馆藏通过多对多关系相互联系。 Therefore, I have 2 concerns: 因此,我有两个问题:

  1. Should I have 2 arrays with 2 ids in each of the 3 collections, or one join collection with 3 ids? 我应该在3个集合中的每个集合中拥有2个具有2个ID的数组,还是一个具有3个ID的联接集合?
  2. How to perform reads, inserts, updates and deletes, so everything is in sync and integrity is ensured? 如何执行读取,插入,更新和删除操作,从而确保一切都同步并确保完整性?

For most scenarios, I'd probably have the referencing IDs on each of the objects, like this: 对于大多数情况,我可能在每个对象上都有引用ID,如下所示:

{
  "_id": "123",
  "firstReferenceCollectionId": "abc",
  "secondReferenceCollectionId": "def"
}

If your application is going to have massive scale, I'd probably further denormalize the data based on how it's actually being used. 如果您的应用程序要大规模发展,我可能会根据数据的实际使用情况进一步对数据进行非规范化。

To answer your second question, you really shouldn't need to worry about that with the above approach, since the internal id of the reference won't change when other properties on those objects change. 要回答您的第二个问题,您真的不需要担心使用上述方法,因为当这些对象上的其他属性更改时,引用的内部ID不会更改。 If you go the route of additional denormalization, use meteor add matb33:collection-hooks to sync up data on upserts. 如果您采用额外的非规范化路线,请使用meteor add matb33:collection-hooks来同步upserts上的数据。 Here's the documentation link: https://github.com/matb33/meteor-collection-hooks 这是文档链接: https : //github.com/matb33/meteor-collection-hooks

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM