I have a MongoDB collection that I have imported from a CSV file. In that collection, I have a "BirthDate" field, which is a string "YYYY-MM-DD". I want to be able to search for people who were born before 1990 for example. To do that, I have a JSON query which looks like:
{
"BirthDate": {$lt: "YYYY-MM-DD"}
}
But the problem I have is that it also returns all the documents in which the BirthDate is an empty string (field not filled in the CSV file). It works fine if I want to search people who were born AFTER 1990:
{
"BirthDate": {$gt: "YYYY-MM-DD"}
}
How can I tell MongoDB to ignore empty strings when I look for people born BEFORE a date?
Thanks