@@ -207,19 +207,21 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
207207 }
208208
209209 for field_name , field_type in model .__fields__ .items ():
210+ if field_name == "timestamp" :
211+ continue
210212 lookup_field = (
211213 model .collection_name () if hasattr (model , "collection_name" ) else model .__name__
212214 )
213215 mongo_field = new_collections .get (lookup_field , field_name .lower ())
214- full_field_name = f"{ prefix } { mongo_field } "
216+ full_mongo_field_name = f"{ prefix } { mongo_field } "
215217
216218 if field_name == "unit" :
217219 unit_field_name = f"{ prefix } { mongo_field } _unit"
218220 pipeline ["unit" ] = f"${ unit_field_name } "
219221 match_conditions [unit_field_name ] = {"$exists" : True }
220222 else :
221- pipeline [full_field_name ] = f"${ full_field_name } "
222- match_conditions [full_field_name ] = {"$exists" : True }
223+ pipeline [field_name ] = f"${ full_mongo_field_name } "
224+ match_conditions [full_mongo_field_name ] = {"$exists" : True }
223225
224226 if field_name in nested_fields :
225227 if get_origin (field_type .type_ ) is List :
@@ -228,24 +230,22 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
228230 )
229231 pipeline [field_name ] = {
230232 "$map" : {
231- "input" : f"${ full_field_name } " ,
233+ "input" : f"${ full_mongo_field_name } " ,
232234 "as" : "item" ,
233235 "in" : {
234236 k : f"$$item.{ v .replace ('$' , '' )} " for k , v in nested_pipeline .items ()
235237 },
236238 }
237239 }
238- match_conditions [full_field_name ] = {"$exists" : True , "$ne" : []}
240+ match_conditions [full_mongo_field_name ] = {"$exists" : True , "$ne" : []}
239241 else :
240242 nested_pipeline , nested_match = create_nested_pipeline (
241- nested_fields [field_name ], f"{ full_field_name } ."
243+ nested_fields [field_name ], f"{ field_name } ."
242244 )
243245 pipeline [field_name ] = nested_pipeline
244- match_conditions .update (
245- {f"{ full_field_name } .{ k } " : v for k , v in nested_match .items ()}
246- )
246+ match_conditions .update ({f"{ field_name } .{ k } " : v for k , v in nested_match .items ()})
247247
248- logger .debug (f"Field: { field_name } , Full field name: { full_field_name } " )
248+ logger .debug (f"Field: { field_name } , Full mongo field name: { full_mongo_field_name } " )
249249 logger .debug (f"Resulting pipeline part: { pipeline [field_name ]} " )
250250
251251 logger .debug (f"Final pipeline for { model .__name__ } : { pipeline } " )
0 commit comments