Is findOne() in MongoDB deprecated? I am asking this because when I use findOne() in WebStorm the IDE puts a line through findOne() and gives a message saying findOne() is deprecated and to find substitute.

I looked in the MongoDB documentation to try and find an answer but it did not mention anything about findOne() being deprecated.

If findOne() is deprecated what would be the best alternative to this method?

If it is not deprecated does anyone know why WebStorm gives this warning?

Any help with this is appreciated! Thanks!

3 Answers 3


It looks like findOne() is only deprecated in the Javascript driver.

Worse, MongoDB node driver uses findOne internally extensively. The change was made last year, as part of a series of commits carrying the helpful message "clean up docs".

I have no idea why the maintainer added the deprecation warning, so I've created a bug report to remove it: https://jira.mongodb.org/browse/NODE-723


Just got an answer from the maintainer of the nodejs driver, deprecation has been removed!


  • What do you know, peer pressure works! Normally I'd recommend against opening known duplicate tickets (even if its for a different version), but this one got the job done so I can't complain much ;-)
    – Guss
    Dec 8, 2016 at 9:59

I just ran into the same problem...it took a while to find, but the deprecation is documented in the native driver for Node:

use find().limit(1).next(function(err, doc){})

This is for the 2.1.20 version of mongodb.

  • So does this mean that findOne() is only deprecated when using MongoDB's node package?
    – Tim
    May 30, 2016 at 14:42
  • so in order to do the same thing as findOne() would I just do find({_id: id}).limit(1).each(function (error, dbValueIWantInJson) { console.log(dbValueIWantInJson); }); I am not sure what the best way to use find().limit(1).next(function(err, doc){}) ?
    – Tim
    May 30, 2016 at 17:38
  • @Tim I did something similar to: collection.find({ _id: id }).limit(1).next(function(findErr, results) { ...do stuff with results... } Jun 1, 2016 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.