I have one problem regarding return value of count function of db.collection.find.count()
; namely my program should return integer value (number of documents in db.collection
by certain criteria), but function returns Promise
which I don't know how to use in callback function.
I tried to make callback function inside count()
method like count(function(err,res){ if(err) console.log('Error') else count1=res;})
,but it doesnt work. i also searched stackoverflow and mongodb documentation, and tried some other solutions but it didn't help also. (but when i tried db.collection('blogCollection').find("author":"user123").count()
in robomongo, it correctly ran and displayed result of query)
This is my code var count1=database.collection("blogCollection").find({"author":id}).count();
where count1
should be the number of documents where author
field equals to id
value. Thank you in advance for helping.:) My mongodb is 3.2 version, and node is v10.15.3.