From 363aefe399efc6acc035a846241acd136ca8277d Mon Sep 17 00:00:00 2001 From: Eddie Linder Date: Thu, 20 Dec 2018 01:09:28 +0200 Subject: [PATCH] Get rid of _get_as_pymongo wrapper altogether as we return raw output --- mongoengine/queryset/base.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index 5493ffac..8ae88422 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -188,7 +188,7 @@ class BaseQuerySet(object): ) if queryset._as_pymongo: - return queryset._get_as_pymongo(queryset._cursor[key]) + return queryset._cursor[key] return queryset._document._from_son( queryset._cursor[key], @@ -690,7 +690,7 @@ class BaseQuerySet(object): self._document._from_son(doc, only_fields=self.only_fields)) elif self._as_pymongo: for doc in docs: - doc_map[doc['_id']] = self._get_as_pymongo(doc) + doc_map[doc['_id']] = doc else: for doc in docs: doc_map[doc['_id']] = self._document._from_son( @@ -1486,7 +1486,7 @@ class BaseQuerySet(object): raw_doc = six.next(self._cursor) if self._as_pymongo: - return self._get_as_pymongo(raw_doc) + return raw_doc doc = self._document._from_son( raw_doc, _auto_dereference=self._auto_dereference, @@ -1833,19 +1833,6 @@ class BaseQuerySet(object): return tuple(data) - def _get_as_pymongo(self, doc): - """Clean up a PyMongo doc, removing fields that were only fetched - for the sake of MongoEngine's implementation, and return it. - """ - # If the _id was not included in a .only or was excluded in a .exclude, - # remove it from the doc (we always fetch it so that we can properly - # construct documents). - fields = self._loaded_fields - if fields and '_id' in doc and fields.value == QueryFieldList.EXCLUDE and '_id' in fields.fields: - del doc['_id'] - - return doc - def _sub_js_fields(self, code): """When fields are specified with [~fieldname] syntax, where *fieldname* is the Python name of a field, *fieldname* will be