1

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?

Farhan Yaseen
  • 2,507
  • 2
  • 22
  • 37
hadlog
  • 105
  • 1
  • 1
  • 7

0 Answers0