Skip to content

Commit

Permalink
Attempt to fix nested model retrival
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Oct 3, 2024
1 parent 110ed46 commit ba2ef4a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions opensensor/collection_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,15 @@ def get_nested_fields(model: Type[BaseModel]):
return nested_fields


def create_nested_pipeline(model: Type[BaseModel], prefix=""):
def create_nested_pipeline(model: Type[BaseModel], prefix="", pipeline=None):
logger.debug(f"Creating nested pipeline for model: {model.__name__}, prefix: {prefix}")
nested_fields = get_nested_fields(model)
match_conditions = {}
pipeline = {
"_id": False,
"timestamp": "$timestamp",
}
if pipeline is None:
pipeline = {
"_id": False,
"timestamp": "$timestamp",
}

for field_name, field_type in model.__fields__.items():
if field_name == "timestamp":
Expand Down Expand Up @@ -240,7 +241,7 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
match_conditions[full_mongo_field_name] = {"$exists": True, "$ne": []}
else:
nested_pipeline, nested_match = create_nested_pipeline(
nested_fields[field_name], f"{field_name}."
nested_fields[field_name], f"{full_mongo_field_name}.", pipeline
)
pipeline[field_name] = nested_pipeline
match_conditions.update({f"{field_name}.{k}": v for k, v in nested_match.items()})
Expand Down

0 comments on commit ba2ef4a

Please sign in to comment.