Nosql多对多 [英] Nosql many-to-many

查看:139
本文介绍了Nosql多对多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档数据库设计中处理多对多关系的可接受模式是什么?

解决方案

您想要什么对多对多进行建模将取决于您要询问哪种查询,如何更新数据等等。。。假设我们有与酒吧相关的foos。

您可以将foo建模为

  {
'bars': ['bar1','bar2','bar3']
}

并建立模型a

  {
'foos':['foo_x','foo_y','foo_z']
}

或者您可以将foo和bar之间的图形或关系建模为单个文档本身

  {
从:'foo1',
到:'bar1'
}

{
来自: foo1,
到: bar2
}

{
来自: foo2,
到:'bar3
}

{
from'foo3',
到:'bar3'
}

还有很多其他方法。如何实现将取决于您要问的问题,要支持的操作,要提高的效率以及数据库中可用的索引。


What is the accepted pattern for handling many-to-many relationships in a document database design?

解决方案

How you want to model the many-to-many will depend on what kind of queries you want to ask, how you want to update the data, etc... Say we have foos related to bars in a many to many fashion.

You could model a foo as

{
   'bars': ['bar1', 'bar2', 'bar3']
}

and model a bar as

{
   'foos': ['foo_x', 'foo_y', 'foo_z']
}

Or you could model the graph or relations between foo and bar as individual documents themselves

{
    from: 'foo1',
    to: 'bar1'
}

{
   from: 'foo1',
   to: 'bar2'
}

{  
   from: 'foo2',
   to: 'bar3
}

{
  from 'foo3',
  to: 'bar3'
}

There are plenty of other ways too. How you want to do it will depend on the questions you want to ask, the operations you want to support, what you want to be efficient, and the indexing available in the database.

这篇关于Nosql多对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆