Hi - I'm trying to work with MongoDB UpdateMany method but cannot seem to get my table.recordUpdates structured correctly.
Can someone provide a simple example of how to do this?
March 4, 2022, 4:13pm
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):
Then, you create an updateOne query that has dynamic values for each value from your recordUpdates:
Let me know if you think this would be helpful for your use case!
By this answer do you mean updateMany does not work with MongoDB? If it does can you provide an example, I'm also trying to get this to work
March 16, 2022, 8:35pm
It does work in Retool. For example, this query updates all sales in the users table to be equal to 10
March 16, 2022, 8:36pm
Let us know if you're seeing any errors with your query
October 1, 2022, 10:31am
Can you provide an example on how to update the whole row? I'm trying to use table.recordUpdates to update the db with table values.
However, it would require me to remove the _id from the object.
Performing an update on the path '_id' would modify the immutable field '_id'
I'd like to know how to do this right from the Update.
October 11, 2022, 8:42pm
@yeh Thanks for reaching out. If you only need to reference recordUpdates, you could do something like this (using _.omit()):
However, I'd typically recommend following the JS query mapped approach:
Sorry Tess, I have a doubt, your JSCode return a
query3, whats this? where you do define it?
Otherwise what I want to do is to manually edit the fields in the table and when I save them, update fields on my MongoDB table.
March 15, 2023, 10:33pm
@Raul_Vazquez_Mendez thanks for checking in! Realizing my post was a bit confusing.
The Mongo query (in my third screenshot above and posted again below) is named "query3"
So the JS query shown in my previous message triggers this query and passes in dynamic values for the _id, _name, and number: