What is returned from Mongoose query that finds no matches?

后端 未结 2 1448
太阳男子
太阳男子 2021-01-30 20:59

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

相关标签:
2条回答
  • 2021-01-30 21:37

    If conditions were valid but no matches were found:

    • find: err is null, result is []

    • findOne and findById: err is null, result is null

    However, if some condition was invalid (e.g. field is string but you pass an object, or you pass an invalid _id)

    For all three: err is {..}, result is undefined

    0 讨论(0)
  • 2021-01-30 21:38

    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.

    0 讨论(0)
提交回复
热议问题