Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

node.js - What is returned from Mongoose query that finds no matches?

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:

  1. err = null, results = []
  2. err = null, results = null
  3. err = error document, results = null
question from:https://stackoverflow.com/questions/18214635/what-is-returned-from-mongoose-query-that-finds-no-matches

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...