You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "shunnNet (via GitHub)" <gi...@apache.org> on 2023/08/20 07:57:29 UTC
[GitHub] [airflow] shunnNet commented on issue #33076: [MongoHook] support creation of time series collections
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org