improve aggregation expression parsing by reyannh · Pull Request #619 · mongomock/mongomock

Conversation

@reyannh

Make expressions starting with $$ROOT or $$CURRENT work on documents with array of embedded documents fields.
Consider the following document dict:
{'name': 'foo', 'errors': [{'error_type': 1, 'description': 'problem 1'}, {'error_type': 2, 'description': 'problem 2'}], '_id': ObjectId('5e8c9ac81e957db62b16b888')}
And the expression - $$ROOT.errors.error_type
Current code will throw KeyError exception - {KeyError}2

@codecov

@pcorpet

Thanks for suggesting this improvement. Please add some tests in test__mongomock, both to check that the behavior is the same as with pymongo + MongoDb and that your feature doesn't get broken by a later refactoring.

robberry90 pushed a commit to robberry90/mongomock that referenced this pull request

Feb 4, 2023
Co-authored-by: Pascal Corpet <pascal@bayesimpact.org>

2 participants

@reyannh @pcorpet