H
H
HellishCode2020-12-10 12:49:10
MongoDB
HellishCode, 2020-12-10 12:49:10

How to make a selection in MongoDB by time?

Good afternoon.
The database has an array of data. Each entry in the array has a sent_at property .
How can I get only the data sent_at, which is not more than 1 minute from the current time?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2020-12-13
@HellishCode

First you have to calculate the current time minus 1 minute

const date = new Date();
date.setMinutes(date.getMinutes() - 1);

Now make a selection for those values ​​that are less than this time:
TableName.find( { sent_at: { $lte: date } } )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question