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

LM91
  • 53
  • 1
  • 7
  • 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. – Sufyan Jamil Aug 11 '15 at 13:44
  • http://stackoverflow.com/questions/5825520/in-mongoose-how-do-i-sort-by-date-node-js – dsgdfg Aug 11 '15 at 14:00
  • @SufyanJamil Thanks for your answer, I have added a minimum condition and it worked! – LM91 Aug 12 '15 at 07:41

0 Answers0