'In MongoDB, can we get distinct values of a field regardless of hierarchy?
I am creating an application to store and display multiple hierarchies. I am storing json data in nested tree format like the following
{
"text":"Node1",
"children":
[{
"text":"Node2",
"children":[...]
},
{
"text":"Node3",
"children":[...]
}]
}
Is there a way to get the distinct values for the field text regardless of where the field appears in hierarchy. It could be the text of the parent, child, grandchild or further descendants.
Desired output is ["Node1","Node2","Node3",...]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
