I am using nodes and native MongoDB drivers to create an application. I want to make sure that a record exists with a specific situation and I want to know which method is better?
collection.find ({...}). Count (function (count, count) {if (calculation> 0) {// blah blah}}) or
collection.findOne ({...}, Function (mistake, object) {// blah blah}}
See I believe find with the border (1) is the way to go in your case. (If you receive the actual document data with the query If you want to do this, use findOne .) In the context of mongodb-native , the code will look something like this function recordsexists (selector, callback) {collection.find (selector, {limit: 1}, function (mistake, cursor) {ifrr return callback (error); cursor count (function (err, cnt) {Return callback (err, !! cnt);});});}
I'm a bit confused about this: collection.find ({...}). The original driver allows to do this? Is it cursor.count ? Anyway, border your friend is here
Comments
Post a Comment