What is returned from Mongoose query that finds no matches?
database, mongodb, mongoose, node.js
Solution
It depends on the query. If it is a `find`, then `results == []`. If it is a `findOne`, then `results == null`. No errors if everything else is ok.
Problem
I'm a little confused reading the Mongoose documentation. If I run a query in mongoose which matches no documents in the collection, what are the values of `err` and `results` in the callback function `callback(err, results)`? I just don't know what Mongoose considers an "error". As a mathematician, returning the empty set (i.e. `results` array empty) seems perfectly valid and shouldn't be an "error" - the query executed fine, there was just no matching documents. On the other hand, some may consider it an "error". From mongoose docs, either: - `err` = null, `results` = [] - `err` = null, `results` = null - `err` = error document, `results` = null