I have an Email
document which has a sent_at
date field:
{
'sent_at': Date( 1336776254000 )
}
If this Email
has not been sent, the sent_at
field is either null, or non-existant.
I need to get the count of all sent/unsent Emails
. I'm stuck at trying to figure out the right way to query for this information. I think this is the right way to get the sent count:
db.emails.count({sent_at: {$ne: null}})
But how should I get the count of the ones that aren't sent?
If the sent_at field is not there when its not set then:
If its there and null, or not there at all:
Refer here for querying and null
Use:
Which counts all emails whose sent_at property is null or is not set. The above query is same as below.
Seems you can just do single line:
If you want to ONLY count the documents with
sent_at
defined with a value ofnull
(don't count the documents withsent_at
not set):