Using a MongoDB Trigger to Update Collection with async HTTP Request

I have a project where I need to get a bunch of item data via an API for an online game’s marketplace. The way their system works plus the amount of calls I’d need to make means that doing it all from within my application isn’t possible.

I was using Google Sheets with a script + timer, but it’s long past time I migrated to an actual database system for better support, ability to optimize, and of course, to learn and grow.

So, I’m using and learning MongoDB and am working to write a Trigger function(s) to auto-update these documents every x amount of time. This means using passing the itemId for each doc (item) into an async function that fires an HTTP Request out to an endpoint and using that value to set a field.

What I have tried currently looks like:

exports = async function()
   var coll ="myCluster").db("myDB").collection("myColl");

     [{ $set: { lastUpdate: new Date(), itemPrice: await getPrice($"itemId") } }])
   .then(result =>
      // some logging
   .catch block to log errors

async function getPrice(itemId)
   // do an await context.http.get() with the url + itemId
   // parse out the JSON and return the data I want

I know I can use a field to set another field and have had no trouble with that. I could replace the await getPrice with "$itemId" and it would copy the value from the one field to the other.

If I place the field string into a function, however, it seems to resolve the function and just send the string literal instead of evaluating the field for the result first. So, I’m guessing this is some issue with how/when prvalues (or Mongo/Atlas/JS’s version of them) are evaluated?

It feels like using the Aggregation Pipeline is the right move here considering what the documentation says about it, but I can’t find anything talking about calling functions using field values as parameters.