Time series
Store measurements with their time and metadata in buckets and query them as single documents.
Store measurements with their time and metadata in a time series. TeselaDB groups them in buckets by time and metadata. Queries return the measurements one by one.
Requirements
- A user with
dbAdminorreadWriteon the database to create collections.
Create
JavaScript
db.createCollection("readings", {
timeseries: { timeField: "ts", metaField: "sensor", granularity: "minutes" },
expireAfterSeconds: 2592000,
});Insert and query
JavaScript
db.readings.insertOne({ ts: new Date(), sensor: { id: 7 }, temperature: 21.4 });
db.readings.find({ "sensor.id": 7 }).sort({ ts: -1 }).limit(10);Check
The query returns the latest measurements of the sensor as separate documents, with the time, the meta field and the fields.
Common problems
- Do not read the raw buckets with
rawData, because their_idvalues and format differ from MongoDB's.