Hello I dont want empty records, the resulting records should look a bit like the following, I had to unwind and then group again for the sorting to take place, which I think it’s not ideal but at least it works.
In this case I looked up for bee, so it matched all performers with .bee. all events containing .bee. and all venues containing .bee., to get rid of the empty records I tried to $match $ne on the record, but then I realized that this would only bring results if ALL the subdocuments would match .bee., in this case as we have all records containing .bee. it would bring the result without the empty records, however if I would search for a venue .*sunshine.grove. using $match after the $unwind stage gets me no records because there are no performers matching .*sunshine.grove. however I do need that the result comes back as a venue, even tho there are no performers named .*sunshine.grove.
Additionaly to try to match for non empty records after $unwind, I have tried to filter those out in the $group stage with no success. Here is the updated query:
This is the result set, in this case it’s correct, minus the empty record in performer
[
{
performers: [
[],
[
{
_id: 701,
name: 'Atlantic City Beer & Music Festival',
segment: {
name: 'Music',
uid: 'e062293a-9b46-11ed-8aab-0242ac130005'
},
bio: null,
homepage: 'https://www.acbeerfest.com/',
uid: 'f35adf69-1cb0-41d6-91ab-9cb330566c91',
genre: {
uid: '506a0d84-d310-471f-8d56-b863f91dc69b',
name: 'Undefined'
},
type: [],
subtype: [],
websites: {
facebook: 'https://www.facebook.com/acbeerfest/',
instagram: 'https://www.instagram.com/acbeerfest/',
twitter: 'https://twitter.com/acbeerfest'
}
}
],
[
{
_id: 855,
name: 'Beenie Man',
segment: {
name: 'Music',
uid: 'e062293a-9b46-11ed-8aab-0242ac130005'
},
bio: null,
homepage: 'http://www.beenieman.net/',
uid: 'cd19510e-f7d4-4f30-a177-eb3382c95fdf',
genre: {
uid: '152b15b3-91d4-11ed-a212-0242ac130003',
name: 'Reggae'
},
type: [],
subtype: [],
websites: {
lastfm: 'http://www.last.fm/music/Beenie+Man',
musicbrainz: '0d85b9f2-802d-48bb-aa85-6a9668869053',
wiki: 'https://en.wikipedia.org/wiki/Beenie_Man'
}
}
]
],
events: [
{
uid: '4199441d-2c40-4cac-936a-4c357ba83d69',
title: 'Okeechobee Music & Arts Festival',
type: 'Festival',
start: ISODate("2023-03-02T00:00:00.000Z"),
performers: {
names: [
'Austin Millz',
'Baby Keem',
'Big Boi',
'Biig Piig',
'Blunts & Blondes',
'Boogie T',
'Break Science'
],
total: 62
},
venue: 'Sunshine Grove',
country: 'United States',
state: 'Florida',
city: 'Okeechobee'
},
{
uid: 'e46e3dc8-1327-4130-aab3-f09c250e54d0',
title: "PSW & Pherm Brewing present a night of Phun with The Last Rwind (DC's Phish Tribute), Pherm Brewing Beer specials and give aways",
type: 'Generic',
start: ISODate("2023-03-11T01:00:00.000Z"),
performers: { names: [], total: 0 },
venue: 'Pearl Street Warehouse',
country: 'United States',
state: 'District of Columbia',
city: 'Washington'
},
{
uid: '870dac81-5964-48dd-8bc8-d830f29bc440',
title: 'Decibel Metal & Beer Fest - 2 Day Pass',
type: 'Generic',
start: ISODate("2023-04-14T00:00:00.000Z"),
performers: {
names: [
'All Out War',
'Decibel Metal & Beer Fest',
'Drowning Man',
'Escuela Grind',
'Eyehategod',
'Frozen Soul',
'Fuming Mouth'
],
total: 15
},
venue: 'The Fillmore Philadelphia',
country: 'United States',
state: 'Pennsylvania',
city: 'Philadelphia'
}
],
venues: [ [] ]
}
]