Mongoose query where value is not null

wesbos picture wesbos · May 14, 2013 · Viewed 108.7k times · Source

Looking to do the following query:

Entrant
    .find
      enterDate : oneMonthAgo
      confirmed : true
    .where('pincode.length > 0')
    .exec (err,entrants)->

Am I doing the where clause properly? I want to select documents where pincode is not null.

Answer

numbers1311407 picture numbers1311407 · May 14, 2013

You should be able to do this like (as you're using the query api):

Entrant.where("pincode").ne(null)

... which will result in a mongo query resembling:

entrants.find({ pincode: { $ne: null } })

A few links that might help: