How do I populate or run dynamic mongo queries

We have an internal reporting feature we are migrating to Retool, however, we can't really figure out how to populate MongoDB queries or run dynamic queries where inputs are values being looped over.

Our current workflow: https://gist.github.com/sambhav2612/138793fff55538c95105a6b5f388f6a0

The fact that it is completely async might make it all-the-more difficult to migrate in our assumption but we'd like a try anyway. We just want to replicate the TypeScript code for now to offload the spikes our reporting tool causes to our app directly to the MongoDB server.

Hi @sambhav2612! Thanks for reaching out.

You can use .trigger() in a JS query to trigger Mongo queries and you can pass data from the JS query to dynamically populate your mongodb query. It sounds like that would be helpful here?

For example, you can loop over recordUpdates and trigger a separate mongo query for each record:

Copyable code:

tableX.recordUpdates.forEach(function(record, index) {
mongoUpdateOne.trigger({
additionalScope: {
'i': index,
},
})
})

Then the Mongo query that will be triggered by the JS code:

We have docs on scripting in Retool: https://docs.retool.com/docs/scripting-retool

Let me know if this makes sense, or if you have any additional questions!