Which Model Tree Structure should I use here?

21 views
Skip to first unread message

Anal Terminator

unread,
Nov 8, 2017, 4:04:47 PM11/8/17
to mongodb-user
I have a bunch of menu-submenu data and have two possible ways of storing the documents.

Method 1, where the children are all separate documents with their own children and so on:

{
"_id": "1.1.1.1.2.1.1",
"title": "Panthera",
"children": [
{
"title": "Tiger"
},
{
"title": "Lion"
},
{
"title": "Jaguar"
},
{
"title": "Leopard"
},
{
"title": "Snow Leopard"
},
{
"title": "Clouded Leopard"
}
]
}


Method 2, where each menu item only contains a reference to its parent, without a children array:

{
"_id": "1.1.1.1.2.1.1",
"parentId": "1.1.1.1.2.1",
"title": "Panthera",
"parentTitle": "Felines",
},
{
"_id": "1.1.1.1.2.1.1.1",
"parentId": "1.1.1.1.2.1.1",
"title": "Tiger",
"parentTitle": "Panthera",
} etc, etc...

Which one of these would be the fastest in a case like this. Consider the fact that these are all read-only and will never be edited by the app. Documents with no further children will contain additional,
possibly heavy data. Thanks.

Wan Bachtiar

unread,
Nov 16, 2017, 8:11:13 PM11/16/17
to mongodb-user

Which one of these would be the fastest in a case like this

Hi,

Depends on the result that you’re after. For example, given a menu list all of the direct dependencies (children) ?
If that’s the case see Model Tree Structures with Child References

You can also see various ways to structure tree data on Model Tree Structures.

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages