5

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!

Tim
  • 153
  • 1
  • 5

3 Answers3

5

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

Screenshot

Paul White
  • 94,921
  • 30
  • 437
  • 687
HubertMine
  • 51
  • 1
  • 1
4

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.

2

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

Guss
  • 136
  • 3