I want to get the number of documents in the collection(MongoDB) and then use this variable in another function. But I don't understand why I can't record the result in var above-mentioned?
var countD;
db.db("mongouploads").collection("blocks").countDocuments({}, {}, (err, result) => {
if (err) throw err;
countD = result
});
And then countD
equal undefined. Where is my fault?