Mongoose query where value is not null
I ended up here and my issue was that I was querying for
{$not: {email: /@domain.com/}}
instead of
{email: {$not: /@domain.com/}}
$ne
selects the documents where the value of the field is not equal to the specified value. This includes documents that do not contain the field.
User.find({ "username": { "$ne": 'admin' } })
$nin
$nin selects the documents where: the field value is not in the specified array or the field does not exist.
User.find({ "groups": { "$nin": ['admin', 'user'] } })
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:
- The mongoose query api
- The docs for mongo query operators