Evening Everyone,
New to javascript and trying to execute this same order, that is clearly not happening. When I run in debug mode and when i set the debug point on getMongoField the rest of the code gets executed, How do i make this code execute in the same order, first retrieve some fields from mongo and then sendFirstmessage and then sendSecondMessage(all three functions returns a promise), can introduce await inside promise?
Thank you
sentTest: (message) => {
    return new Promise((resolve, reject) => {
        let mongoRecord = null;
        let asResponse;
        let doc = getMongoField('terminals', {'attributes.XYZ': 'ABC'}).then(function (docs) {
            console.info('Before ', mongoRecord)
            mongoRecord = docs
            console.info('After', mongoRecord)
        })
        ts.sendFirstMessage(mongoRecord.attributes.sno, mongoRecord, mongoRecord.attributes.value).then(function (result) {
        //do nothing
        })
        ts.SendSecondMessage(docs.attributes.sno, 'Test', docs, message).then(function (response) {
            resolve(response);
        })
    })
},
 
     
     
    