从Mongoose查询返回的查找没有匹配项? [英] What is returned from Mongoose query that finds no matches?
问题描述
我有点困惑阅读Mongoose文档。
I'm a little confused reading the Mongoose documentation.
如果我在mongoose中运行一个没有匹配集合中的文档的查询,则 err
结果
在回调函数 callback(err,results)
?我只是不知道Mongoose认为一个错误。作为一个数学家,返回空集合(即 results
数组为空)似乎完全有效,不应该是一个错误 - 查询执行得很好,只有没有匹配文件。另一方面,有些人可能认为它是错误。从mongoose文档,可以:
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
=错误文档,results
= null
err
= null,results
= []err
= null,results
= nullerr
= error document,results
= null
推荐答案
这取决于查询。如果是 find
,则 results == []
。如果是 findOne
,则 results == null
。如果一切正常,没有错误。
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.
这篇关于从Mongoose查询返回的查找没有匹配项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!