-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
[BUG] Array order is not consistent #414
Comments
It seems This query in MongoDB compass: { '_id': { $in: [ObjectId('63701201e4a0b602dfa188a8'), ObjectId('637011fbe3ae5cc480291a65')] } } return things in order. But: topics1 = await Topic.find(In(Topic.id, topic_id_list)).to_list()
topics2 = await Topic.find({'_id': {'$in': topic_id_list}}).to_list() is not. |
Hi, Thank you for the issue. It is very reasonable. |
Thank you for your kind response. |
This issue is stale because it has been open 30 days with no activity. |
This issue was closed because it has been stalled for 14 days with no activity. |
@roman-right Other than OP, the order on my setups is always the same when using As this issue was closed by stale bot, I'd suggest reopening it. |
@roman-right The above lines replaced with: ids.append(PydanticObjectId(link.ref.id)) # casting to be sure to have a comparable ObjectId, as type-hinting says "Any" for `DBRef.id`
docs = await model_class.find(In("_id", ids), with_children=True, fetch_links=fetch_links).to_list() # type: ignore
docs.sort(key=lambda d: ids.index(d.id))
return docs The overhead should be low, but of course, there is more overhead than not sorting anything. |
First of all, thank you for this great library!
Describe the bug
I have a hierarchy of documents such as a course that will have multiple linked topics in an array. I put functionality in my FastAPI backend app, to change the order of topics. I see that in MongoDB Compass that the array is in the right order. But every time I call the endpoint, the Beanie Document object will return the array, not in the right order.
To Reproduce
![image](https://user-images.githubusercontent.com/965723/201496305-addfab5b-d418-4eec-897d-fd9ac334ca63.png)
Here is what the document looks like:
Here is the things needed to get the doc:
And here is how I check the result:
output:
Expected behavior
It should return an array in the right order.
Additional context
The text was updated successfully, but these errors were encountered: