I've set of new Mongodb scripts for every release and i'm trying to create NodeJS utility to run the scripts by reading from .txt files which are there in folder.
Ex: In 1.txt file i've this command db.getCollection("users").createIndex({ name: 1 }); and i want to run using NodeJS
I've NodeJs program like below
const { MongoClient } = require("mongodb");
const uri = "mongodb:uri";
const client = new MongoClient(uri);
async function run() {
try {
await client.connect();
const db = client.db("employee");
// I want to run above script like here. How can i do it?
const result = await db.command({
dbStats: 1,
});
console.log(result);
} finally {
await client.close();
}
}
run().catch(console.dir);