Workflow MongoDB updateLoop

I am trying to use Workflows to call an API and populate the results into a MongoDB collection. I have tried to follow this example MongoDB Update Many Example - #2 by Tess and this example How do I populate or run dynamic mongo queries - #2 by Tess.

However in the workflow if I create a function called updateOne that populates the MongoDB and a Javascript loop that triggers this I get an error updateOne.Trigger is not a function

I just want to iterate each record in the array from an api and insert a new record if it does not exist or update an existing record if it does exist.

Hey @Rob_Duncan! You can definitely do this, though the syntax is a bit off.

Our docs on functions in workflows should help a bit.

  1. Turn function passed to map be an async function.

  2. Instead of updateOne.trigger({additionalScope}), you'll invoke the function with parameters like you would in traditional JS, and await it's return.
    return await updateOne(row.id, row.name)

  3. Add 2 parameters to the function definition to use as the variables in the filter and update sections.


Let me know if that helps!