-
-
Notifications
You must be signed in to change notification settings - Fork 168
Replace deprecated MongoDB option #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@backflip Hi, thank you for this PR. I think, we can't replace it like that. This package is used with many different versions of One option is to check mongodb-native package version and use appropriate option. |
Very good point, sorry for missing that. I have added a proposal for reading the |
@backflip This looks good. Could you also write a couple of tests to make sure it works as expected? |
Should this maybe cache the version info into a variable to avoid doing the full |
@animir, I did not find a way of getting the version from the driver. There was a discussion about exposing it: mongodb/node-mongodb-native#2709 |
Update: It seems to work via |
@backflip You can stub a connected Mongo Client and test it for a case when |
@@ -235,7 +257,7 @@ class RateLimiterMongo extends RateLimiterStoreAbstract { | |||
const where = Object.assign({ key: rlKey }, docAttrs); | |||
|
|||
return this._collection.deleteOne(where) | |||
.then(res => res.result.n > 0); | |||
.then(res => res.deletedCount > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered this while testing with the real clients: v4 does not return result
anymore. Seems to be in line with https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered this while testing with the real clients: v4 does not return
result
anymore. Seems to be in line with https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/
Should it be selected depending on driver version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It worked fine with 3.6.9, but let me do some digging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this was updated in https://github.com/mongodb/node-mongodb-native/pull/2651/files#diff-06ad5e5a8b0f21c69f986da5545842d224dd5a79c054081bc35d714e4bdc6077. However, it just mentions that Our CRUD result types have been out-of-sync with the official drivers CRUD specification for some time
. I could not find any old specs where result
was part of the response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@backflip deletedCount
is supported at least from MongoDB Server 3.2 http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#~deleteWriteOpResult It is safe to use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@backflip Did it brake tests, where delete
function used? I see 3 mocks with result.n
mocked for those tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@backflip never mind above question. I see you already took care of that 👍
Updated accordingly. Thanks for the input, @ainkinen! |
Should I remove the non-stubbed tests or keep them? They helped me discover that the |
The |
@backflip There is no infrastructure for real MongoDB connection in test environment. I understand, tests with real database can help in some cases, but it also brings new level of complexity. Let's keep stabbed tests for this PR. |
Fair enough. 👍 |
|
||
it('consume 1 point (driver v3)', (done) => { | ||
const testKey = 'consume1v3'; | ||
sinon.stub(mongoClient, 'topology').value({ s: { options: { metadata: { driver: { version: '3.6' } } } } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@animir, does this make sense as a mock? I'm checking the resulting upsertOptions
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@backflip yes, this looks good
The
returnOriginal
option forfindOneAndUpdate
is deprecated, see https://github.com/mongodb/node-mongodb-native/blob/f916843ad2002a4c829c5f126e58e8efba257525/lib/collection.js#L1720This should get rid of warnings like
[MONGODB DRIVER] DeprecationWarning: collection.findOneAndUpdate option [returnOriginal] is deprecated and will be removed in a later version.