'python mongoening time series collection support

I was looking for a solution for storage and retrieval of time series data.

As I have mongodb set up already in my project, I searched for a solution with mongodb and mongoengine (instead of pymongo).

So I wonder if there a similar solution to this for mongoengine or if there ain't one, how-to develop it.

{
   "_id" : ObjectId("60c0d44894c10494260da31e"),
   "source" : {sensorId: 123, region: "americas"},
   "airPressure" : 99 ,
   "windSpeed" : 22,
   "temp" : { "degreesF": 39,
              "degreesC": 3.8
            },
   "ts" : ISODate("2021-05-20T10:24:51.303Z")
}

db.createCollection("weather", {
  timeseries: {
    timeField: "ts",
    metaField: "source",
    granularity: "minutes"
  },
    expireAfterSeconds: 9000 
}); 

Sample code is taken from MongoDB's New Time Series Collections in which the solution by pymongo is described but I wanna do it with mongoengine. Is that possible?



Solution 1:[1]

try to create your time-series collections with pymongo like this:

import pymongo

connection= pymongo.MongoClient('mongodb://localhost')
db = connection.<dbName>

db.create_collection('<tsCollectionName>', timeseries={ 'timeField': '<timeField>', 'metaField': '<metaField>', 'granularity': '<granularity>' }) })

you can replace every value between <> with yours

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1