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)
| 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. :: |