Hi guys,
I have an aggregation pipeline query which outputs a BSON object with a key-value pair, value being an array of strings:
db.dataGroupSchema.aggregate([
{
"$project":{
"_id":1,
"dataSourceId":"$dataSourceIds.value"
}
},
{
"$unwind":"$dataSourceId"
},
{
"$group":{
"_id":"$dataSourceId",
"count":{
"$sum":1
}
}
},
{
"$match":{
"count":{
"$gt":0
}
}
},
{
"$group":{
"_id":"",
"duplicatedDataSourceIds":{
"$push":"$_id"
}
}
},
{
"$project":{
"duplicatedDataSourceIds":1,
"_id":0
}
}
]);
output:
{
“duplicatedDataSourceIds” : [
“a75de0d0-df16-4618-9d3e-73c59b5137a5”,
“3a83da20-3524-4fb7-aeda-26e1daadc214”,
“450fdceb-13f1-4e4d-9ac7-4890b35268f1”,
“409c68ea-d600-42f5-ab3f-d29aac86fc68”
]
}
I want to reuse this array as a variable so I want just an array of strings without a key and not in an object. Similar to the result of the distinct():
db.dataGroupSchema.distinct("dataSourceIds.value")
[
“3a83da20-3524-4fb7-aeda-26e1daadc214”,
“409c68ea-d600-42f5-ab3f-d29aac86fc68”,
“450fdceb-13f1-4e4d-9ac7-4890b35268f1”,
“a75de0d0-df16-4618-9d3e-73c59b5137a5”
]
Is there an option to do it in plain vanilla mongo script?