Hello everyone,
I’m trying to write an aggregation to return information about my sources and I can’t find a simple way to union values of arrays of the documents I group.
Source docs
{
"_id" : "123",
"C" : "C1",
"K" : "K1" ,
.....(much more fields)
"Fs" : [
"F1","F3"
]
},
{
"_id" : "264",
"C" : "C1",
"K" : "K1" ,
.....(much more fields)
"Fs" : [
"F2","F3"
]
}
Wanted Doc
{
"_id" : { "C" : "C1", "K" : "K1" }
.....(much more fields)
"Fs":[
"F1","F2","F3"
]
}
I managed to obtain this result using an $unwind before my $group; but my question is:
There’s a simple way to use just one $group step? Something equivalent to a SQL Union.
Thanks