• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

What would findOne() in mongoDB return if the record does not exists?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am making a signUp service. my function at backend should return an error if email already exists in the database.
Here is my function at the backend to handle my post method before posting I am checking if the user with the same emailId exits or not.
At line 5, I am checking if some user exits with the emailId entered in the form(sent as a request to the function).
The MongoDB documentation says findOne() will return a cursor when it finds a record for the query provided in the argument.
I want to know what it returns when it could not able to find the record for the provided query.

Please provide a way around.

 
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Blitz,
findOne done not return cursor but single document. "Find" returns cursor.  In case "findOne({"query"}) " is not able to fins any matched document then it returns "null".

Regards,
Vikas
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic