@@ -207,19 +207,21 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
207
207
}
208
208
209
209
for field_name , field_type in model .__fields__ .items ():
210
+ if field_name == "timestamp" :
211
+ continue
210
212
lookup_field = (
211
213
model .collection_name () if hasattr (model , "collection_name" ) else model .__name__
212
214
)
213
215
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 } "
215
217
216
218
if field_name == "unit" :
217
219
unit_field_name = f"{ prefix } { mongo_field } _unit"
218
220
pipeline ["unit" ] = f"${ unit_field_name } "
219
221
match_conditions [unit_field_name ] = {"$exists" : True }
220
222
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 }
223
225
224
226
if field_name in nested_fields :
225
227
if get_origin (field_type .type_ ) is List :
@@ -228,24 +230,22 @@ def create_nested_pipeline(model: Type[BaseModel], prefix=""):
228
230
)
229
231
pipeline [field_name ] = {
230
232
"$map" : {
231
- "input" : f"${ full_field_name } " ,
233
+ "input" : f"${ full_mongo_field_name } " ,
232
234
"as" : "item" ,
233
235
"in" : {
234
236
k : f"$$item.{ v .replace ('$' , '' )} " for k , v in nested_pipeline .items ()
235
237
},
236
238
}
237
239
}
238
- match_conditions [full_field_name ] = {"$exists" : True , "$ne" : []}
240
+ match_conditions [full_mongo_field_name ] = {"$exists" : True , "$ne" : []}
239
241
else :
240
242
nested_pipeline , nested_match = create_nested_pipeline (
241
- nested_fields [field_name ], f"{ full_field_name } ."
243
+ nested_fields [field_name ], f"{ field_name } ."
242
244
)
243
245
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 ()})
247
247
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 } " )
249
249
logger .debug (f"Resulting pipeline part: { pipeline [field_name ]} " )
250
250
251
251
logger .debug (f"Final pipeline for { model .__name__ } : { pipeline } " )
0 commit comments