INNER CODE UNIT · Python

parse

mongomock/mongomock · mongomock/aggregate.py:238

    def parse(self, expression):
        """Parse a MongoDB expression."""
        if not isinstance(expression, dict):
            # May raise a KeyError despite the ignore missing key.
            return self._parse_basic_expression(expression)

        if len(expression) > 1 and any(key.startswith('$') for key in expression):
            raise OperationFailure(
                f'an expression specification must contain exactly one field, '
                f'the name of the expression. Found {len(expression)} fields in {expression}'
            )

        value_dict = {}
        for k, v in expression.items():
            if k in arithmetic_operators:
                return self._handle_arithmetic_operator(k, v)
            if k in project_operators:
                return self._handle_project_operator(k, v)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…