microsoft/TypeScriptSamples

imageboard typings for mongodb do not have definition for findOne

rkaramc opened this issue · 9 comments

It seems findOne has been deprecated on the mongodb api, and the .d.ts has been updated to remove this method. Can the sample be updated to use a different method?

Sure, thanks for the heads up. I'm not familiar with MongoDB, so what's a better method to use?

I think find().limit(1) would work a lot better. Here is a link that might help explain why findOne was deprecated. Hope this helps!

A PR would be appreciated.

I just looked into it a bit further and found that findOne() shows up in webStorm as deprecated but in the MongoDB documentation it does not mention it as depreciated. I initially only read the first part of the post on the site I gave but after reading a bit further I found that there is no discrepancy with findOne that the updated answered question found. Sorry if I caused any confusion...

It looks like it is only deprecated for node. The recommended replacement is find().limit(1).next(function(err, doc){}) but when I substitute this I get a type error for .next.

I found a work around using each... find({_id: id}).limit(1).each(function (error, dbValueIWantInJson) { console.log(dbValueIWantInJson); });... but I want to wait on creating a pull request until the following is addressed by the mango community because findOne() deprecation may get reverted.

the collection method findOne is marked as deprecated since 2.0, while other driver implementations do offer it with no deprecation marks.

I created a pull request after the mongoDB community replied to the post explaining why findOne has been deprecated. They recommended using .batchSize(10).next(). There is no method next() on batchSize() for the Node.js MongoDB driver API version that imageboard uses. in this case nextObject() is a suitable substitute for the current version that imageboard uses. Please review and merge.

You're welcome! Glad to help.