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

Method with_id

mongoengine/queryset/base.py:753–764  ·  view source on GitHub ↗

Retrieve the object matching the id provided. Uses `object_id` only and raises InvalidQueryError if a filter has been applied. Returns `None` if no document exists with that id. :param object_id: the value for the id of the document to look up

(self, object_id)

Source from the content-addressed store, hash-verified

751 return result
752
753 def with_id(self, object_id):
754 """Retrieve the object matching the id provided. Uses `object_id` only
755 and raises InvalidQueryError if a filter has been applied. Returns
756 `None` if no document exists with that id.
757
758 :param object_id: the value for the id of the document to look up
759 """
760 queryset = self.clone()
761 if queryset._query_obj:
762 msg = "Cannot use a filter whilst using `with_id`"
763 raise InvalidQueryError(msg)
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.

Calls 4

cloneMethod · 0.95
InvalidQueryErrorClass · 0.90
firstMethod · 0.45
filterMethod · 0.45