您想要如何对多对多进行建模取决于您想要提出什么样的查询、您想要如何更新数据等等...假设我们有与多对多方式的 bar 相关的 foo。
你可以将 foo 建模为
{
'bars': ['bar1', 'bar2', 'bar3']
}
Run Code Online (Sandbox Code Playgroud)
并将酒吧建模为
{
'foos': ['foo_x', 'foo_y', 'foo_z']
}
Run Code Online (Sandbox Code Playgroud)
或者您可以将 foo 和 bar 之间的图表或关系建模为单独的文档本身
{
from: 'foo1',
to: 'bar1'
}
{
from: 'foo1',
to: 'bar2'
}
{
from: 'foo2',
to: 'bar3
}
{
from 'foo3',
to: 'bar3'
}
Run Code Online (Sandbox Code Playgroud)
还有很多其他方法。您想要如何做到这一点取决于您想要提出的问题、您想要支持的操作、您想要提高效率以及数据库中可用的索引。