collection.find({description : data.story.description}, function(err, cursor){
cursor.each(function(err, item){
if(item != null){
console.log("duplicate found\n"+util.inspect(item));
}
})
})
Is it possible to get the size of the cursor, without using a counter in the each loop?
If you are checking for duplicates, you may wish to try the count() method attached to collection. E.g.:
collection.count({description: data.story.description}, function(err, count) { if (count > 1) console.log("Duplicates found!"); });Cursor.toArray() is just using cursor.each() on the back end. My example assumes you are checking post-insert(), but you could check pre- with (count > 0) and call insert() if (count == 0).