1 year ago
#332524
Udhayha Karthik
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",...]
mongodb
mongodb-query
distinct-values
0 Answers
Your Answer