I have an Email
document which has a sent_at
date field:
{
\'sent_at\': Date( 1336776254000 )
}
If this E
Use:
db.emails.count({sent_at: null})
Which counts all emails whose sent_at property is null or is not set. The above query is same as below.
db.emails.count($or: [
{sent_at: {$exists: false}},
{sent_at: null}
])
You can also try this:
db.emails.find($and:[{sent_at:{$exists:true},'sent_at':null}]).count()
If you want to ONLY count the documents with sent_at
defined with a value of null
(don't count the documents with sent_at
not set):
db.emails.count({sent_at: { $type: 10 }})
db.employe.find({ $and:[ {"dept":{ $exists:false }, "empno": { $in:[101,102] } } ] }).count();
Seems you can just do single line:
{ "sent_at": null }
If the sent_at field is not there when its not set then:
db.emails.count({sent_at: {$exists: false}})
If its there and null, or not there at all:
db.emails.count({sent_at: null})
Refer here for querying and null