Edit: I have seen the problem is estimatedDocumentCount()
function.
As the documentation explain it will ‘Returns the count of all documents in a collection or view’.
I think you expect the count
from the query, not from the collection.
So, insted of estimatedDocumentCount()
you have to use countDocuments()
.
By the way, if you check todayAdded.length
it should be equal 0.
Try this query:
var result = await model.find({
"owner": "...",
"createdAt": {
"$gte": new Date(2016, 11, 16),
"$lt": new Date(2016, 12, 01)
}
}).countDocuments(function(err, count) {
console.log("Number of docs: ", count);
});
CLICK HERE to find out more related problems solutions.