How can I check a column for null values ​​in node -orm

I am using the orm package in node.js and I am trying to query the database using find() on one of my models. However, I cannot figure out how to check a column for NULL values ​​with find() . Is there any way to do this?

+8
javascript database orm
source share
2 answers

If the sent_at field does not exist, if it is not set, then:

 db.emails.find({sent_at: {$exists: false}}) 

If it is there and null or not at all:

 db.emails.find({sent_at: null}) 

Link: Query for nul fields

Note. . Since you did not specify the database name or the orm name that you used, provided the database is mongodb.

Hope this helps.

+1
source share

How about putting null in a condition

 schema.find({ col: null}, function (err, people) { … }); 

or

 schema.count({ col: null }, function (err, count) { console.log("We have %d Does in our db", count); }); 

The documentation also says that you can make Raw requests

 db.driver.execQuery( "SELECT * FROM table WHERE col IS NOT NULL", function (err, data) { ... } ) 
0
source share

All Articles