Hello, im new in Retool and im trying to build a loop inside my rawbody.
I will explain you my problem.
I have a Connection to MongoDB and a Connection to a APi.
I want to make multiple post request to the API but dont like to copy my customers 1000 times and add it to the API the request is always the same like just some fields should get change with the data from MongoDB.
{
"bulk_connections": {
"connection": [
{
"customer_code": "XXXX",
"customer_name": "XXXXXX",
"customer_alias": "XXXXXXXXXXXX",
.....
the XXXX should replace with the MongoDB data as a loop like this.
MongoDB.data[i].customer_code.
I dont think you can do this as some sort of strapped on JS on the mongoDB query. You have to first query the DB and then have a query that loops through that query triggering an additional scope like @ugo.ago suggested above. That new query should return all promises as data payload.
Like this maybe:
const arr = mongoDB.data.map(x=>x.customer_code) //your array of things to iterate over
const query = API // your query to trigger for each
const promises = arr.map((item) => {
return query.trigger({
additionalScope: {
assignment_id: item //assignment_id would be available inside {{assignment_id}} in the target query when run
}
});
});
return Promise.all(promises)