diff --git a/ming/base.py b/ming/base.py index de3073f..0d17040 100644 --- a/ming/base.py +++ b/ming/base.py @@ -4,6 +4,8 @@ import warnings from collections import defaultdict from datetime import datetime +# from typing import Iterable, Sequence +from collections.abc import Sequence import bson from bson import Decimal128 @@ -74,7 +76,7 @@ def __init__(self, cls, cursor, allow_extra=True, strip_extra=True, find_spec=No self.cursor = cursor self._allow_extra = allow_extra self._strip_extra = strip_extra - self.find_spec = find_spec + self.find_spec = find_spec or {} def __iter__(self): return self @@ -96,10 +98,12 @@ def distinct(self, *args, **kwargs): return self.cursor.distinct(*args, **kwargs) def limit(self, limit): + self.find_spec['limit'] = limit self.cursor = self.cursor.limit(limit) return self def skip(self, skip): + self.find_spec['skip'] = skip self.cursor = self.cursor.skip(skip) return self @@ -108,6 +112,12 @@ def hint(self, index_or_name): return self def sort(self, *args, **kwargs): + if args: + if isinstance(args[0], list): + sort = args[0] + else: + sort = args + self.find_spec['sort'] = sort self.cursor = self.cursor.sort(*args, **kwargs) return self