什么是表示具有属性的多对多关系的最"mongo"方式?
例如:
Intro
MYSQL表
people
=> firstName, lastName, ...
Movies
=> name, length ..
peopleMovies
=> movieId, personId, language, role
Solution 1
把人植入电影中...?
在MongoDB中,我知道denormalize and embed
人很好,但我不想让embed
人进入电影,这在逻辑上没有任何意义.因为人们不一定只属于电影.
Solution 2
People
and Movies
will be two separate collections.
People
=> embed [{movieId: 12, personId: 1, language: "English", role: "Main"} ...]
Movies
=> embed [{movieId: 12, personId: 1, language: "English", role: "Main"} ...]
这个解决方案的问题是,当我们想要为特定的movie
更新一个人的role
时,我们需要运行两个更新查询,以确保两个集合中的数据同步.
Solution 3
我们还可以做一些关系更密切的事情,比如最终得到三个集合
People
=> firstName, lastName, ...
Movies
=> name, length ..
Castings
=> movieId, personId, language, role
The issue with this is that because of the lack of a join statement in MongoDB, it would take 3 queries
to go from people -> movies and vice versa.
这里是我的问题,还有什么其他方法可以在MongoDB
和更NoSQL
的方式中模拟类似的东西.就所提供的解决方案而言,在mongo,哪种解决方案在性能和惯例方面最好.