You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Detail:
we have a aggregate pipeline with a stage:
{'$lookup': {'from': 'security_info', 'localField': 'github_url', # join the security info table with git
'foreignField': 'github_url', 'as': 'security_info'}},
{'$set': {'security_info': {'$filter': {'input': '$security_info', 'as': 'security_info', 'cond': {
'$eq': ['$$security_info.branch', '$branch']}}}}}, # also match with branch
{'$set': {'security_info': {'$arrayElemAt': ['$security_info', 0]}}}, # turn security field from array to object
It works on our test database on mongo compass, but it fails when using mongomock, with exception
self = <mongomock.aggregate._Parser object at 0x7f7df7ae2b00>
operator = '$arrayElemAt', values = ['$security_info', 0]
def _handle_project_operator(self, operator, values):
if operator in _GROUPING_OPERATOR_MAP:
values = self.parse(values) if isinstance(values, str) else self.parse_many(values)
return _GROUPING_OPERATOR_MAP[operator](values)
if operator == '$arrayElemAt':
key, index = values
array = self._parse_basic_expression(key)
index = self.parse(index)
> return array[index]
E IndexError: list index out of range
.local/lib/python3.6/site-packages/mongomock/aggregate.py:370: IndexError
The text was updated successfully, but these errors were encountered:
From mongodb's document: https://docs.mongodb.com/manual/reference/operator/aggregation/arrayElemAt/
If idx exceeds the array bounds, $arrayElemAt does not return a result.
However, mongomock seems didn't check the out of range case. if the idx exceeds the array bounds, it throws an IndexError: list index out of range.
A simple range check here(
mongomock/mongomock/aggregate.py
Line 376 in b507ae6
Detail:
we have a aggregate pipeline with a stage:
It works on our test database on mongo compass, but it fails when using mongomock, with exception
The text was updated successfully, but these errors were encountered: