"name" : "UniqueCompany
"array1" : [
{
"company" : {
"name" : "string1"
}
},
{
"company" : {
"name" : "string2"
}
},
{
"company" : {
"name" : "string3"
}
},
{
"company" : {
"name" : "string4"
}
},
{
"company" : {
"name" : "string5"
}
}
I want to retrieve all name values of the Unique Company in one set(all combined to one result). How will I write the query to mongo using node.js. I tried this but did not work:
collection.aggregate([
{
$match: {
"name": UniqueCompany
},
{
$group : {
_id : {name : "$name"},
companies : {$push: "$array1.company.name"}
}
}
])
Thanks in advance. This is a practice problem that I was doing and I am always stuck when dealing with double nested array.
via The_Programmer
No comments:
Post a Comment