V
V
Vitaly2021-09-26 16:31:35
MongoDB
Vitaly, 2021-09-26 16:31:35

How does $gt and $lt work in mongo?

Help me deal with the keys in $gt and $lt in mongo correctly
I use them to filter by the time of writing to the database.
For example, I want to get data from 8 am yesterday to 8 am today, in which case I have
$gt == date yesterday 08:00:00
$lt == date today 08:00:00

What exactly will the database return to me, all records starting from 8:00:00 inclusive to 8:00:00 or a record that was made exactly at 08:00:00 will not be in the answer?
So will $lt == 08:00:00 return records up to and including 08:00:00 from a document created on 08:00:00 or will the last document be a document created at 07:59:59?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
syxme, 2021-10-21
@syxme

$gt = Greater than // date > dateInTable
$lt = Less than // date < dateInTable
$gte = Greater than inclusive // ​​date >= dateInTable
$lte = Less than inclusive // ​​date <= dateInTable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question