0

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

3
  • 2
    use both less than and greater than condition. you can use first javascript date as the minimum condition. or add condition for not equals to null or empty. Commented Aug 11, 2015 at 13:44
  • stackoverflow.com/questions/5825520/… Commented Aug 11, 2015 at 14:00
  • @SufyanJamil Thanks for your answer, I have added a minimum condition and it worked! Commented Aug 12, 2015 at 7:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.