MongoDB集合中可以包含另一个集合吗? [英] Can a MongoDB collection have inside it another collection?

查看:580
本文介绍了MongoDB集合中可以包含另一个集合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要存储一个递归树结构.链表.
因此,所有对象都是相同的.每个都有一个指向父对象的指针,每个都有一个子对象数组.
我可以在Mongo中存储这样的结构吗?
即一个父对象的Mongo集合,每个对象中都包含一个子对象的Mongo集合.

I need to store a recursive tree structure. A linked list.
So all the objects are the same. Each has a pointer to a parent object and each has an array of child objects.
Can I store such a structure in Mongo.
i.e. A Mongo collection of parent objects, each object holds within it a Mongo collection of child objects.

$a = $MyCollection->findOne(**some conditions)->Childs->find(...)

推荐答案

您不能将集合存储在集合中.但是您可以将引用对象的ID存储在其他集合中.您将不得不将ID解析为文档或元素,然后,如果该元素存储了更多ID,则需要不断解析这些ID.文档本应具有丰富且重复的数据,但是在文档中它们确实说明了嵌入而不是嵌入,您只能使用ids

You cant store collections in collections. But you can store ids that reference objects in other collections. You would have to resolve the id to the document or element and then if that element stores more ids you would need to resolve those on and on. Documents are meant to be rich and duplicate data but in the docs they do explain that instead of embedding you can just use ids

这篇关于MongoDB集合中可以包含另一个集合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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