Mongo Db父母和孩子标签相关的其他集合领域 [英] Mongo Db parents and children tags related to other collections fields

查看:139
本文介绍了Mongo Db父母和孩子标签相关的其他集合领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我要为一个小网站设置我的mongo db模式,我需要的是将此模式重现为mongo db集合:

Well , i'm going to set up my mongo db schema for a little site, what i need is to reproduce this schema into mongo db collections:

product
        -> tag1
              ->child_tag1
              ->child_tag2
        -> tag2
              ->child_tag1
              ->child_tag2
        -> tag3
              ->child_tag1
              ->child_tag2

用mongo重现这个模式的方法?

which is the best way to reproduce this schema with mongo ?

确定我需要能够更改标签或子标签而不更新所有集合对象:)

For sure i need to be able to change a tag or child tag without update all collection objects :)

我知道我的问题不是很清楚,我需要澄清,我试图将一个mysql db站点转换到一个mongoDb网站。

Well cause of i know my question is not so clear, i need to clarify that i'm trying converting a mysql db site onto a mongoDb site.

所以我有4个表在mysql:

So i have 4 tables in mysql:

products

id(AUTO) | product_name | qty
 1          biscuits      34
 2          limonade      29

tags

id(AUTO) |  tag_name 
  1            sugar
  2            eggs
  3            vitamine C

tags_childs

id(AUTO) | id_tag | tag_child_name
  1          1        glucouse
  2          2        protein
  3          2        chicken
products_tags

id_product | id_tag | id_tag_child 
  1            1         NULL
  1            1         1
  1            2         3
  2            3        NULL

所以我使用products_tags表加入超过4个表(这就是为什么加热连接我切换到mongoDb:))

so i use products_tags table to join over 4 tables (and this is why heating joins i'm switching to mongoDb :))

我可以重现这个场景与mongodb集合和对象?

so i can reproduce this scenario with mongodb collections and objects?

thx :)

推荐答案

了解您的上述文件显示;基本上许多产品可以有许多标签,标签可以有他们下的孩子(编码标签 - > Php是编码的子标签)。

Just wanted to make sure I'm understanding what your above document shows; essentially Many Products can have Many Tags, and Tags can have children under them (Coding tag -> Php is child tag of Coding).

这是我的理解上面的问题这里是我将如何构造您的Mongo集合:

With that being my understanding of the above question here's how I would structure your Mongo Collections:

产品集合:

{
   "ProductName":"Sweet Jelly",
   "Qty":9,
   "Tags":[
     ListOfTagIds
    ]
 }

TagIds列表将是唯一标识符,mongoDB会自动分配给创建的每个新字段.. 请参见这里

The list of TagIds would be the Unique Identifiers which mongoDB automatically assigns to each of the new fields created.. see here

从这里我创建一个标签集合:

From there I'd create a Tags Collection:

{
  "TagName":"Coding Languages";
  "ChildTags":[
      $_idOfChildren
   ]
}


$ b b

然后,如果您的标签有一个子级:

Then if your tag had a child:

{ 
  "TagName":"PHP",
}

对于这个父/子关系,你可以从这个优秀的mongo资源位于此处: Mongo Book - 第16页从无加入开始。

For this Parent / Child relationship you can read a bit more about it from this excellent mongo resource located here: Mongo Book - Page 16 starting with No Joins.

祝你好运!

这篇关于Mongo Db父母和孩子标签相关的其他集合领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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