Skip to content

Commit b3f9f50

Browse files
committed
attempt to generalize the collection projection
1 parent 9d2966e commit b3f9f50

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

opensensor/collection_apis.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ def create_model_instance(model: Type[BaseModel], data: dict):
231231
# Handle flat models (like Pressure) that have a single main field
232232
if len(model.__fields__) == 2 and "timestamp" in model.__fields__:
233233
main_field = next(field for field in model.__fields__ if field != "timestamp")
234-
mongo_field = new_collections.get(model.__name__, main_field.lower())
234+
lookup_field = (
235+
model.collection_name if hasattr(model, "collection_name") else model.__name__
236+
)
237+
mongo_field = new_collections.get(lookup_field, main_field)
235238
if main_field not in data and mongo_field in data:
236239
data[main_field] = data[mongo_field]
237240

0 commit comments

Comments
 (0)