So I'm really new to MongoDB and document storage stuffs. I'm having a hard time trying to find the most elegant and efficient solution to do the following:
I have a collection called tests. In each tests there are actions with a field owner. See below:
{
"_id" : ObjectId("528c731a810761651c00000f"),
"actions" : [
{
"action" : "6784",
"owner" : "MERCHAND_1",
"_id" : ObjectId("528c7292810761651c00000e")
},
{
"action" : "1",
"owner" : "MERCHAND_1",
"_id" : ObjectId("528c7292810761651c00000d")
},
{
"action" : "1358",
"owner" : "MERCHAND_2",
"_id" : ObjectId("528c7292810761651c00000c")
}
],
"name" : "Test 1",
"product" : ObjectId("528bc4b3a0f5430812000010")
}
How can I have a list (array) of each distinct owner value using Node.js & MongoDB (I'm using mongoose driver). Is it better to do it on mongoside or node.js side? If for example I run the function on the previous table, it should return:
[
{
"owner":"MERCHAND_1"
},
{
"owner":"MERCHAND_2"
}
]