Skip to content

Commit 8e9f278

Browse files
committed
attempt to generalize the collection projection
1 parent 4e58c0f commit 8e9f278

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

opensensor/collection_apis.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
204204
pipeline = {}
205205

206206
for field_name, field_type in model.__fields__.items():
207-
full_field_name = f"{prefix}{field_name}"
207+
lookup_field = (
208+
model.collection_name() if hasattr(model, "collection_name") else model.__name__
209+
)
210+
mongo_field = new_collections.get(lookup_field, field_name.lower())
211+
full_field_name = f"{prefix}{mongo_field}"
208212

209213
if field_name in nested_fields:
210214
if get_origin(field_type.type_) is List:
@@ -362,18 +366,6 @@ def get_uniform_sample_pipeline(
362366
project_pipeline = create_nested_pipeline(response_model)
363367
project_pipeline["timestamp"] = "$timestamp"
364368

365-
# # Handle flat models (like Pressure, LiquidLevel, pH) that have a single main field
366-
# if len(response_model.__fields__) == 2 and "timestamp" in response_model.__fields__:
367-
# main_field = next(field for field in response_model.__fields__ if field != "timestamp")
368-
# lookup_field = (
369-
# response_model.collection_name()
370-
# if hasattr(response_model, "collection_name")
371-
# else response_model.__name__
372-
# )
373-
# mongo_field = new_collections.get(lookup_field, main_field.lower())
374-
# project_pipeline[main_field] = f"${mongo_field}"
375-
# logger.info(f"Mapping {mongo_field} to {main_field} for model {response_model.__name__}")
376-
377369
logger.info(f"Project pipeline for {response_model.__name__}: {project_pipeline}")
378370

379371
pipeline = [

0 commit comments

Comments
 (0)