Q:

What is the most efficient way to store a tree data structure in MongoDB?

I was thinking the simplest thing would be a flat list:
{
  id: ObjectId()
  parentId:  ObjectId()
  value: ‘foo’,
}

Just one big collection. To find the child nodes of a node, just search through the list and find all instances where the parentId equals the current node id. Indexes on id/parentId. 
This might be faster for writes, but reads might become pretty horrific.
And we will have a lot more reads than writes!
MongoDB has some sort of built in tree data structure:
https://docs.mongodb.com/manual/applications/data-models-tree-structures/
But I am wondering how that differs from a flat list like the one I proposed.

A:

If you define an index on id and an index on parentId, find the children of a node should be really fast.
Why do you think it'll be horrific?

UPDATE: The worst case scenario would be O(log N) but it's important to note that the bucket size Mongo uses is 8192 (source). That means there's a really small constant multiplying this time which means MongoDB operations can be quite fast.

