-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
find_one with update ignores sorting #883
Comments
Hi @KarlCMB , But I'll think if it can be supported with a few workarounds. For now I'd suggest fetching and updeting after. |
Hi @roman-right |
Would it be possible to implement findAndModify? I have a queue-style use case much like this but I'd love to be able to find, update, and return the most recent document all in one atomic query. edit: I see find_and_modify is deprecated in pyMongo, but find_one_and_update might work |
@slingshotvfx just do a regular find and update with limit=1 |
That works, but returns a PyMongo UpdateResult so you still have to do a second query right after to read the just-updated item from the database. |
You can use the UpdateResponse to control the behaviour |
UpdateMany doesn't take a So you can |
Describe the bug
When using update immediately after find_one, the sorting order is ignored.
If I only use "find_one", the order is correct though
To Reproduce
Expected behavior
I expect the order is correct
The text was updated successfully, but these errors were encountered: