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

Method only

mongoengine/queryset/base.py:1038–1054  ·  view source on GitHub ↗

Load only a subset of this document's fields. :: post = BlogPost.objects(...).only('title', 'author.name') .. note :: `only()` is chainable and will perform a union :: So with the following it will fetch both: `title` and `author.name`:: post = Blog

(self, *fields)

Source from the content-addressed store, hash-verified

1036 return distinct
1037
1038 def only(self, *fields):
1039 """Load only a subset of this document's fields. ::
1040
1041 post = BlogPost.objects(...).only('title', 'author.name')
1042
1043 .. note :: `only()` is chainable and will perform a union ::
1044 So with the following it will fetch both: `title` and `author.name`::
1045
1046 post = BlogPost.objects.only('title').only('author.name')
1047
1048 :func:`~mongoengine.queryset.QuerySet.all_fields` will reset any
1049 field filters.
1050
1051 :param fields: fields to include
1052 """
1053 fields = {f: QueryFieldList.ONLY for f in fields}
1054 return self.fields(True, **fields)
1055
1056 def exclude(self, *fields):
1057 """Opposite to .only(), exclude some document's fields. ::

Callers 15

reloadMethod · 0.80
scalarMethod · 0.80
test_slicingMethod · 0.80
test_onlyMethod · 0.80
test_all_fieldsMethod · 0.80
test_limitMethod · 0.80
test_skipMethod · 0.80

Calls 1

fieldsMethod · 0.95

Tested by 15

test_slicingMethod · 0.64
test_onlyMethod · 0.64
test_all_fieldsMethod · 0.64
test_limitMethod · 0.64
test_skipMethod · 0.64