Run scripts against mongodb from a "javascript query"

Hey There

I want to to run a custom script in my Retool app to update my MongoDB collections. In order to do that I created a javascript query. The script have two `.updateOne' statements:

import { MongoClient, ObjectID } from "mongodb";
const uri = "<connection string uri>";
const client = new MongoClient(uri);
async function run() {
    const db = client.db("sample_mflix");
    const newId = ObjectID()
        {"_id":ObjectID( {{}} )},
        {"$set": {"parent_ref": newId}}
        {"_id": ObjectID({{ModifiedGsesTable.selectedRow._idStudy}}), "Datasets.DatasetID": {{ModifiedGsesTable.selectedRow._idDataset}} },
        {"$set": {"Datasets.$._id": newId}}

I chose a javascript query because I wanted to use the same dynamiclly generated newId
for both update operations.

Is there a better way to do this instead of using a javascript query.

If not, how to:

  1. Dynamically get the connection string to my mongodb resource.
  2. Import the mongodb library.

Roy A