use test17;
db.createCollection(
"weather",
{
timeseries: {
timeField: "timestamp",
metaField: "metadata",
granularity: "seconds"
},
expireAfterSeconds: 86400
}
);
db.weather.insertMany( [
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-18T00:00:00.000Z"),
temp: 12
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-18T04:00:00.000Z"),
temp: 11
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-18T08:00:00.000Z"),
temp: 11
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-18T12:00:00.000Z"),
temp: 12
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-18T16:00:00.000Z"),
timestamp: ISODate("2021-05-18T16:00:00.000Z"),
temp: 16
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-18T20:00:00.000Z"),
temp: 15
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-19T00:00:00.000Z"),
temp: 13
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-19T04:00:00.000Z"),
temp: 12
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-19T08:00:00.000Z"),
temp: 11
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-19T12:00:00.000Z"),
temp: 12
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-19T16:00:00.000Z"),
temp: 17
},
{
metadata: { sensorId: 5578, type: "temperature" },
timestamp: ISODate("2021-05-19T20:00:00.000Z"),
temp: 12
}
] );
db.weather.find({temp:12}); db.weather.countDocuments();
db.weather.insert( { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate("2021-05-19T20:00:00.000Z"), temp: 12, temp: 12 })
db.weather.find({temp:12});
db.weather.countDocuments();