From fca1185935ec1454b5374f2b656d8c9f79d55056 Mon Sep 17 00:00:00 2001 From: Simon Tretter Date: Sun, 8 Jul 2018 17:31:31 +0200 Subject: [PATCH] fix(count-documents): return callback on error case otherwise the scucess handler is called, which results into further missleading errors (e.g. length is not defined) --- lib/operations/collection_ops.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/operations/collection_ops.js b/lib/operations/collection_ops.js index f1e14e8864..e317f982b6 100644 --- a/lib/operations/collection_ops.js +++ b/lib/operations/collection_ops.js @@ -233,7 +233,7 @@ function countDocuments(coll, query, options, callback) { coll.aggregate(pipeline, options, (err, result) => { if (err) return handleCallback(callback, err); result.toArray((err, docs) => { - if (err) handleCallback(err); + if (err) return handleCallback(err); handleCallback(callback, null, docs.length ? docs[0].n : 0); }); });