node.js – How to get the query from the then function?

I’m using a Mongoose query like this:

let Value="START"
myCollection.findOne({param:Value}) .then((doc) => {
    if (!doc) {
        // In this case no document found on my collection.
        // I need to log this case with the parameter 'Value' used for the query.
        // In my example it should be 'START'.
        log(Value) // => Sometimes Value is 'END' due to the asyn and the query delay.
    }
})
Value="END"

Sometime, my query return no value. This is not an error but I need to log the query in this case. Unfortunately, the doc parameter is null. Because it is run async, the “Value” has changed when I enter the then function and I cannot use my “Value” variable.

How can I get the param value inside the then function ?

Read more here: Source link