i have a mongodb collection of events from which i want to get the current availablae events so i am using match query like that
Event.aggregate([ { $match: { isActive: true, ...matchQuery, startDate:{$lt:today}, endDate:{$gt:today} } },])
the problem is that not all the events in my database have startDate and enDate fields and i want to get those events too , so i want to check if startDate and endDate exists then they should be lt and gt than today if they don't exist and the document match the rest of the query , i want to get it . i tried this way but doesn't work
{ $match: { isEnabled: true, ...matchQuery, startDate ? {startDate:{$lt:today}}, endDate ? endDate:{$gt:today} } },
thank you