def exec_js(self, code, *fields, **options):
#        code = self._sub_js_fields(code)

        fields = [QuerySet._translate_field_name(self._document, f) for f in fields]
        collection = self._collection

        scope = {
            'collection': collection.name,
            'options': options or {},
        }

        query = self._query
        if self._where_clause:
            query['$where'] = self._where_clause

        scope['query'] = query
        code = pymongo.code.Code(code, scope=scope)

        return collection.database.eval(code, *fields)
Execute a Javascript function on the server. A list of fields may be
dataset/ETHPy150Open aparo/django-elasticsearch/django_elasticsearch/manager.py/QuerySet.exec_js