Skip to content
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

pymongo.sort supports non-iterable input of a single key #52

Open
harrandt opened this issue Dec 4, 2023 · 3 comments
Open

pymongo.sort supports non-iterable input of a single key #52

harrandt opened this issue Dec 4, 2023 · 3 comments

Comments

@harrandt
Copy link

harrandt commented Dec 4, 2023

pymongo supports .sort("field", 1)

pydantic-mongo's __map_sort only supports an iterable of tuples, for multiple fields:

.sort([("field1", 1), ("field2", -1)])

And there should be an example on this on the main page :) I had to dig this out of the tests.

Artucuno added a commit to Artucuno/pydantic-mongo that referenced this issue Dec 6, 2023
@Artucuno
Copy link
Contributor

Artucuno commented Dec 6, 2023

I think the design of this is intentional, because the find_by method in Pydantic Mongo returns the model and the find method in pymongo returns a Cursor object.

@harrandt
Copy link
Author

harrandt commented Dec 7, 2023

Not sure if that is a valid case, because find_by, of course, should return the model, just in a sorted way. And I don't see how the output type and the sorting of the output is related here.

Artucuno added a commit to Artucuno/pydantic-mongo that referenced this issue Dec 7, 2023
@Artucuno
Copy link
Contributor

Artucuno commented Dec 7, 2023

#45 now supports these as sorting inputs

Union[str, Sequence[Tuple[str, int]], Tuple[str, int]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants