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

Method get

mongoengine/base/datastructures.py:257–279  ·  view source on GitHub ↗

Retrieves an embedded document determined by the given keyword arguments. :param kwargs: The keyword arguments corresponding to the fields to search on. *Multiple arguments are treated as if they are ANDed together.* :return: The embedded document

(self, **kwargs)

Source from the content-addressed store, hash-verified

255 return len(self)
256
257 def get(self, **kwargs):
258 """
259 Retrieves an embedded document determined by the given keyword
260 arguments.
261
262 :param kwargs: The keyword arguments corresponding to the fields to
263 search on. *Multiple arguments are treated as if they are ANDed
264 together.*
265 :return: The embedded document matched by the given keyword arguments.
266
267 Raises ``DoesNotExist`` if the arguments used to query an embedded
268 document returns no results. ``MultipleObjectsReturned`` if more
269 than one result is returned.
270 """
271 values = self.__only_matches(self, kwargs)
272 if len(values) == 0:
273 raise DoesNotExist("%s matching query does not exist." % self._name)
274 elif len(values) > 1:
275 raise MultipleObjectsReturned(
276 "%d items returned, instead of 1" % len(values)
277 )
278
279 return values[0]
280
281 def first(self):
282 """Return the first embedded document in the list, or ``None``

Callers

nothing calls this directly

Calls 3

__only_matchesMethod · 0.95
DoesNotExistClass · 0.90

Tested by

no test coverage detected