S
S
Stanislav2017-01-26 22:54:29
MongoDB
Stanislav, 2017-01-26 22:54:29

How to get the value of a field when selecting?

Whether prompt it is possible as that to learn value of a field in the document at sampling in the condition.
I have some numeric settings in my config

config.basic.i = 10; //10 минут
config.average.i = 20; // 20 минут

The document has a field field equal to either basic or average, as well as a field with the date of the last update updateAt
I need to get a document in which the field
updateAt < new Date(new Date().setMinutes(new Date().getMinutes()-config['$field'].i))

Something like this
Coll.findOne({
    updateAt: {
        $lte: new Date(new Date().setMinutes(new Date().getMinutes()-config['$field'].i))
    }
})

Without approximately such a condition, you will have to receive all documents, compare the field in a cycle, I would not want to do this if you can, of course, avoid this. Maybe with .aggregate it's possible like that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2017-01-26
@ms-dred

Keep a calculated field in the document (updateed - minutes from the document), and use it already

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question