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

Method scalar

mongoengine/queryset/base.py:1270–1291  ·  view source on GitHub ↗

Instead of returning Document instances, return either a specific value or a tuple of values in order. Can be used along with :func:`~mongoengine.queryset.QuerySet.no_dereference` to turn off dereferencing. .. note:: This effects all results and can be unset

(self, *fields)

Source from the content-addressed store, hash-verified

1268 return queryset
1269
1270 def scalar(self, *fields):
1271 """Instead of returning Document instances, return either a specific
1272 value or a tuple of values in order.
1273
1274 Can be used along with
1275 :func:`~mongoengine.queryset.QuerySet.no_dereference` to turn off
1276 dereferencing.
1277
1278 .. note:: This effects all results and can be unset by calling
1279 ``scalar`` without arguments. Calls ``only`` automatically.
1280
1281 :param fields: One or more fields to return instead of a Document.
1282 """
1283 queryset = self.clone()
1284 queryset._scalar = list(fields)
1285
1286 if fields:
1287 queryset = queryset.only(*fields)
1288 else:
1289 queryset = queryset.all_fields()
1290
1291 return queryset
1292
1293 def values_list(self, *fields):
1294 """An alias for scalar"""

Calls 3

cloneMethod · 0.95
onlyMethod · 0.80
all_fieldsMethod · 0.80