MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / in_bulk

Method in_bulk

mongoengine/queryset/base.py:766–789  ·  view source on GitHub ↗

Retrieve a set of documents by their ids. :param object_ids: a list or tuple of ObjectId's :rtype: dict of ObjectId's as keys and collection-specific Document subclasses as values.

(self, object_ids)

Source from the content-addressed store, hash-verified

764 return queryset.filter(pk=object_id).first()
765
766 def in_bulk(self, object_ids):
767 """Retrieve a set of documents by their ids.
768
769 :param object_ids: a list or tuple of ObjectId's
770 :rtype: dict of ObjectId's as keys and collection-specific
771 Document subclasses as values.
772 """
773 doc_map = {}
774
775 docs = self._collection.find({"_id": {"$in": object_ids}}, **self._cursor_args)
776 if self._scalar:
777 for doc in docs:
778 doc_map[doc["_id"]] = self._get_scalar(self._document._from_son(doc))
779 elif self._as_pymongo:
780 for doc in docs:
781 doc_map[doc["_id"]] = doc
782 else:
783 for doc in docs:
784 doc_map[doc["_id"]] = self._document._from_son(
785 doc,
786 _auto_dereference=self._auto_dereference,
787 )
788
789 return doc_map
790
791 def none(self):
792 """Returns a queryset that never returns any objects and no query will be executed when accessing the results

Callers 5

insertMethod · 0.95
_fetch_objectsMethod · 0.80
test_bulkMethod · 0.80
test_scalarMethod · 0.80

Calls 2

_get_scalarMethod · 0.95
_from_sonMethod · 0.80

Tested by 3

test_bulkMethod · 0.64
test_scalarMethod · 0.64