pydantic-mongo
pydantic-mongo copied to clipboard
pymongo.sort supports non-iterable input of a single key
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.
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.
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.
#45 now supports these as sorting inputs
Union[str, Sequence[Tuple[str, int]], Tuple[str, int]]