pydantic-mongo icon indicating copy to clipboard operation
pydantic-mongo copied to clipboard

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

Open harrandt opened this issue 1 year ago • 3 comments

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.

harrandt avatar Dec 04 '23 10:12 harrandt

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.

Artucuno avatar Dec 06 '23 22:12 Artucuno

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.

harrandt avatar Dec 07 '23 08:12 harrandt

#45 now supports these as sorting inputs

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

Artucuno avatar Dec 07 '23 23:12 Artucuno