Create a new or get an existing timeseries PyMongo collection.
(cls)
| 275 | |
| 276 | @classmethod |
| 277 | def _get_timeseries_collection(cls): |
| 278 | """Create a new or get an existing timeseries PyMongo collection.""" |
| 279 | db = cls._get_db() |
| 280 | collection_name = cls._get_collection_name() |
| 281 | timeseries_opts = cls._meta.get("timeseries") |
| 282 | |
| 283 | if collection_name in list_collection_names( |
| 284 | db, include_system_collections=True |
| 285 | ): |
| 286 | collection = db[collection_name] |
| 287 | collection.options() |
| 288 | return collection |
| 289 | |
| 290 | opts = {"expireAfterSeconds": timeseries_opts.pop("expireAfterSeconds", None)} |
| 291 | return db.create_collection( |
| 292 | name=collection_name, |
| 293 | timeseries=timeseries_opts, |
| 294 | **opts, |
| 295 | ) |
| 296 | |
| 297 | def to_mongo(self, *args, **kwargs): |
| 298 | data = super().to_mongo(*args, **kwargs) |
no test coverage detected