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

查看:29
本文介绍了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,您将需要不断地解析它们.文档旨在丰富和重复数据,但在文档中他们确实解释说,您可以使用 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天全站免登陆