Hello, I struggle with creating a Bulk Update in Retool for MongoDB. I can select multiple rows in my table. I designed a Select, where I can define the field I want to bulk update and I add an Input Text for the value I want to replace in bulk. I submit this value with a button. Based on Bulk Update Table Records
I created two queries:
1) JS Code "bulkUpdate" + Event Handler Success Trigger to querybulkUpdate
let col = select1.value;
let value = textInput1.value;
let updates = table1.selectedRows.map(item => ({
filter: { _id: item._id },
update: { [col]: value || "" }
}));
console.log(updates);
return updates;
2) Query updateMany "querybulkUpdate + Event Handler Success table1 Refresh
Find:
{
_id: {$oid:"{{ bulkUpdate.data[i].filter._id }}"}
}
Update:
{
$set:{
"storeLocation": {{ bulkUpdate.data[i].update.storeLocation }},
"couponUsed": {{ bulkUpdate.data[i].update.couponUsed }},
"customer.firstName": {{ bulkUpdate.data[i].update.firstName }},
"customer.lastName": {{ bulkUpdate.data[i].update.lastName }},
"shipping.shippingStatus": {{ bulkUpdate.data[i].update.shippingStatus }},
"shipping.shippingDelayed": {{ bulkUpdate.data[i].update.shippingDelayed }},
"shipping.shippingNo": {{ bulkUpdate.data[i].update.shippingNo }},
"support.assignedAgent": {{ bulkUpdate.data[i].update.assignedAgent }},
"support.lastUpdated": {{ bulkUpdate.data[i].update.lastUpdated }},
"support.support.lastUpdated": {{ bulkUpdate.data[i].update.lastUpdated }},
"support.notes": {{ bulkUpdate.data[i].update.notes }},
"support.priority": {{ bulkUpdate.data[i].update.priority }},
"support.status": {{ bulkUpdate.data[i].update.status }},
"old": {{ bulkUpdate.data[i].update.old }}
}
}
By checking the State of JS bulkUpdate, I get all ids + values in data. (you can see this on the image). But only the first id gets the update in the table. All others not. Both queries run successfully.
Workflow for better understanding: I want to change the tag from Los Angeles (purple) to Online (green).
Thanks for your help!