A lot of users actually use a JS loop & an updateOne query type.
You'll start with a JS query that maps through your .recordUpdates and triggers a new updateOne query for each row (You'll replace id and sales with the values in your table. You'll also want to replace table5 and updateOne with your table name & update query name):
Hi @osirisfrik Hmm, that is strange From what I can tell, this looks to be set up correctly. Are you triggering this on the save changes button in the table?
Can we expand those items in the Retool debug console to see the exact values that are sent from saveChanges to updateOne? (i.e. how was additionalScope defined)
I'd also be curious if hardcoding some values works -- just to confirm there isn't a syntax issue
For example, changing {{_id}} to a hardcoded _id & changing {{readableCode}} to a hardcoded value
Oh right! Thanks for calling that out. I think we're working on some linting to make that more noticeable. Hmm, if you put those values into the updateOne query by hardcoding them, does it also not update?
How are you confirming that the values aren't updating? Are you calling a get request in Retool?
Hello, I have tried these steps but my mongo db instance still doesn't reflect the changes. Also the read lines beneath the params you are passing, isn't that the sign of an error. Please forgive me, I am new to Retool @Tess
Hi @oyinda_david can you share some screenshots? The mongo query will have red lines for the params you're passing in because the values are not defined yet. They'll be defined when you run the JS query
Hello @Tess thank you for your explanation. I didnt understand the earlier explanations, but its clear now. I have been able to update multiple rows in the mongoDB
Hi all! To anyone revisiting this thread to see how to perform multiple updates from a table on Retool to a collection of documents on MongoDB, I wanted to add some additional info. updateMany() works differently than a bulk update in postgres, as it's use case is limited to making one change for multiple documents. Let's say you wanted to change the status of a subset of records to "Complete", then updateMany() would be perfect for that scenario. It can change multiple fields, but it still has to be same change for all records that you're filtering over.
This is not likely to be useful in the context of updating a table in Retool, in which you may be trying to update the individual values of multiple fields in a table, referenced by table1.changesetArray for example. This is why Tess recommends looping over the array and performing an updateOne() for each row. This is perfectly good for a small amount of changes, but I should mention for larger updates (>5 at once) you should use a bulkWrite(). Here's an example of the syntax: