Comments (7)
Hi @KarlCMB ,
This is the MongoDB limitation. The code you wrote is translated into updateOne
query, which doesn't support sorting: https://www.mongodb.com/docs/manual/reference/method/db.collection.updateOne/ .
But I'll think if it can be supported with a few workarounds. For now I'd suggest fetching and updeting after.
from beanie.
Hi @roman-right
thank you for the answer.
If anyone faces the same challenge:
I copied your code from here to solve this issue.
from beanie.
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
from beanie.
@slingshotvfx just do a regular find and update with limit=1
from beanie.
@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.
from beanie.
You can use the UpdateResponse to control the behaviour
from beanie.
UpdateMany doesn't take a response_type
argument unfortunately.
So you can find_one
and update
, return the updated item, but that ignores sort order, or you can find
and update
with limit=1
which works with sorting but doesn't return the updated item or even the updated item id. Unless I'm missing something?
from beanie.
Related Issues (20)
- [BUG] ModuleNotFoundError when importing models in a migration module HOT 1
- [BUG]before_event bug HOT 4
- [BUG] Missing documentation for `beanie.odm.BulkWriter` HOT 1
- [BUG] (some) type annotations for session wrong HOT 3
- [BUG] type annotation for init_beanie() should use Sequence
- [BUG] before_event of type Update HOT 4
- [BUG] mypy does not raise error when trying to access a non-existing attribute from a beanie Document. HOT 1
- [BUG] Indexed unique will not work after Field regex. HOT 2
- [BUG] Empty BackLink for `Optional[BackLink[ADoc]]` when document has no back-link HOT 3
- Concerns and Suggestions Regarding Beanie Library HOT 2
- [Doc] Document for soft delete feature HOT 1
- [BUG] Order of elements in list[Link] is not preserved HOT 2
- [BUG] pydantic computed properties omitted during `insert_many` operation on Document
- [BUG] get_motor_collection() returning None under volume only HOT 1
- [BUG] search criteria not using pydantic Field alias to set the key.
- [BUG] `PydanticObjectId` isn't properly configured when deserializing from JSON
- depth search "find(Teste.item1.item2.item3.id == id)" [BUG]
- [BUG] Link not working in find queries on fields with alias
- [BUG]
- [BUG] BulkWriter does not allow unordered bulks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beanie.