@@ -204,7 +204,11 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
204
204
pipeline = {}
205
205
206
206
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 } "
208
212
209
213
if field_name in nested_fields :
210
214
if get_origin (field_type .type_ ) is List :
@@ -362,18 +366,6 @@ def get_uniform_sample_pipeline(
362
366
project_pipeline = create_nested_pipeline (response_model )
363
367
project_pipeline ["timestamp" ] = "$timestamp"
364
368
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
-
377
369
logger .info (f"Project pipeline for { response_model .__name__ } : { project_pipeline } " )
378
370
379
371
pipeline = [
0 commit comments