shunnNet commented on issue #33076:
URL: https://github.com/apache/airflow/issues/33076#issuecomment-1685217294
@gemunet
The MongoHook use `pymongo` under the ground, it already support time series
collection
You can do it by following
```
mongo_hook = MongoHook(conn_id="mongo_default")
mongo_conn = mongo_hook.get_conn()
mongo_db = mongo_conn["db_name"]
# create time collection here
mongo_db.create_collection("time_test", timeseries= {
"timeField": "timestamp",
"metaField": "metadata",
"granularity": "hours"
})
# use the collection
mongo_collection = mongo_db["time_test"]
# add document
mongo_collection.insert_one(
{
"metadata": { "sensorId": 5578, "type": "temperature" },
"timestamp": dt.utcnow(),
"temp": 12
}
)
```
the mongo_db variable actually pymongo Database object
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]