chilts / mongodb-queue

Message queues which uses MongoDB.
209 stars 91 forks source link

findOneAndUpdate vs findAndModify #13

Closed jsainzvela closed 5 years ago

jsainzvela commented 8 years ago

Hi,

just a clarification. I see you claim to use the findAndModify operation as the basis of the .get() method of your module, but when I dig into the code I just see the following line:

self.col.findOneAndUpdate(query, update, { sort: sort, returnOriginal : false }, function(err, result)

Are those the same operations internally? They are supposed to be different:

https://docs.mongodb.com/manual/reference/command/findAndModify/ https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndUpdate/

Thanks a lot in advance!

Jorge

chilts commented 8 years ago

Oh right, ok, I'll look into it and see what the difference is and whether I should be using the other. :) Many thanks for pointing it out!

jsainzvela commented 8 years ago

Not a prob Andrew, we are just developing something similar (in both Pyton and Perl) and run into the same problem, so I was looking for a "reference implementation".

Thanks!

Jorge

On 3/9/16 7:17, Andrew Chilton wrote:

Oh right, ok, I'll look into it and see what the difference is and whether I should be using the other. :) Many thanks for pointing it out!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chilts/mongodb-queue/issues/13#issuecomment-244527544, or mute the thread https://github.com/notifications/unsubscribe-auth/ALqx5EraPDiF5KZ4p7NMKuArSmmT6Uc9ks5qmQMGgaJpZM4Jzpr-.

chilts commented 7 years ago

I think the code is new functions from the 3.x MongoDB series such as findOneAndUpdate, and the findAndUpdate is deprecated. There was a PR with this information in here from @hanwencheng:

So yeah, I think the docs are wrong there. I'll update them (or in fact, probably remove it and just say it's atomic, so we don't get conflicting info again). :)

Thanks for raising this and sorry it's taken me so long to look into it!

jsainzvela commented 7 years ago

No prob @chilts, thanks to you!

chilts commented 7 years ago

I'll just leave open to remind me to do the docs. :) Thanks.

chilts commented 5 years ago

v4.0.0 was released around 7 months ago and now uses MongoDB v3 driver and should be all up to date now.