MongoDB insertMany or loop to insertOne based on array results

Hey folks! Newbie here...I was trying to follow this guide for what seems like a similar task but with updateOne: MongoDB Update Many Example

I made this updateLoop:

and this mongodb query:

What I am wanting to do is run this query: db.accountpermissions.insertOne({ userId: <userId>, accountId: <accountId>, role: "admin", shadow: true })

But pull the accountId from the table TaxPrepClients:

Total functionality would be to have a button press do Task 1, then in the "After This Query Runs" have it trigger the updateLoop (which probably should be renamed insertLoop) for all entries in the table

There's also a chance that the TaxPrepClients table could be empty, or could have some repeats if new clients have been added. So, some error checking would even better.

Thanks for the help!

Sorted it out!


1 Like