Skip to content

Commit ba2ef4a

Browse files
committed
Attempt to fix nested model retrival
1 parent 110ed46 commit ba2ef4a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

opensensor/collection_apis.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ def get_nested_fields(model: Type[BaseModel]):
197197
return nested_fields
198198

199199

200-
def create_nested_pipeline(model: Type[BaseModel], prefix=""):
200+
def create_nested_pipeline(model: Type[BaseModel], prefix="", pipeline=None):
201201
logger.debug(f"Creating nested pipeline for model: {model.__name__}, prefix: {prefix}")
202202
nested_fields = get_nested_fields(model)
203203
match_conditions = {}
204-
pipeline = {
205-
"_id": False,
206-
"timestamp": "$timestamp",
207-
}
204+
if pipeline is None:
205+
pipeline = {
206+
"_id": False,
207+
"timestamp": "$timestamp",
208+
}
208209

209210
for field_name, field_type in model.__fields__.items():
210211
if field_name == "timestamp":
@@ -240,7 +241,7 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
240241
match_conditions[full_mongo_field_name] = {"$exists": True, "$ne": []}
241242
else:
242243
nested_pipeline, nested_match = create_nested_pipeline(
243-
nested_fields[field_name], f"{field_name}."
244+
nested_fields[field_name], f"{full_mongo_field_name}.", pipeline
244245
)
245246
pipeline[field_name] = nested_pipeline
246247
match_conditions.update({f"{field_name}.{k}": v for k, v in nested_match.items()})

0 commit comments

Comments
 (0)