This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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

Posts: 1
  • Mark post as helpful
  • send pies
  • 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.

Posts: 26
  • Mark post as helpful
  • send pies
  • 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".

To do a great right, do a little wrong - shakepeare. twisted little ad:
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!