These are chat archives for Automattic/mongoose

13th
Dec 2018
ras24
@ras24
Dec 13 2018 06:00

Hello,
How to query datetime with specific range?

I stored a data with datetime every 5 minutes and want to get the data every 10 minutes on 30 minutes ago. I mean, i want to get just 3 data not 6 data on 30 minutes ago.

This is the data :
[ { name: 'Robert', value: '15', createdAt: 2018-10-11T00:00:00.908Z }, { name: 'Robert', value: '48', createdAt: 2018-10-11T00:05:00.621Z }, { name: 'Robert', value: '50', createdAt: 2018-10-11T00:10:00.707Z }, { name: 'Robert', value: '55', createdAt: 2018-10-11T00:15:00.237Z }, { name: 'Robert', value: '45', createdAt: 2018-10-11T00:20:00.530Z }, { name: 'Robert', value: '56', createdAt: 2018-10-11T00:25:00.407Z }, { name: 'Robert', value: '71', createdAt: 2018-10-11T00:30:00.524Z }, ...

I tried to use find and $gte to get data 30 minutes ago

const date = new Date(); date.setMinutes(date.getMinutes() - 30); Data.find({ name: 'Robert', createdAt: { $gte: date } }, '-_id name value', function (err, data) { if (err) return next(err); console.log(data); });
But the query shows all stored data in 30 minutes ago (6 data) or get every 5 minutes of data.

How can i get only every 10 minutes of data? (3 data)