Skip to content

Commit

Permalink
Added support for projections with mongo keywords in
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Aug 15, 2018
1 parent 6ad14a2 commit 1fbd673
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions mongoframes/frames.py
Expand Up @@ -638,18 +638,26 @@ def _flatten_projection(cls, projection):
inclusive = True
for key, value in deepcopy(projection).items():
if isinstance(value, dict):
# Check for $meta projections
if '$meta' in value:
flat_projection[key] = value
continue

# Build the projection value for the field (allowing for
# special mongo directives).
project_value = {
k: v for k, v in value.items()
if k.startswith('$') and k not in ['$ref', '$sub', '$sub.']
}
if len(project_value) == 0:
project_value = True
else:
inclusive = False

# Store a reference/sub-frame projection
if '$ref' in value:
references[key] = value

elif '$sub' in value or '$sub.' in value:
subs[key] = value

flat_projection[key] = True
flat_projection[key] = project_value

elif key == '$ref':
# Strip any $ref key
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -21,7 +21,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.2.12',
version='1.2.13',
description='A fast unobtrusive MongoDB ODM for Python',
long_description=long_description,

Expand Down

0 comments on commit 1fbd673

Please sign in to comment.