Typescript - create db, collection and add json data to the collection

Trying to create collection/database with my typescript. The API succeeds but I don’t see the new collections in compass or through mongosh. Where am I messing up?

Sample code:

import * as mongoDB from "mongodb";
import { MongoClient } from 'mongodb';
const _ = require('lodash');
const fs=require('fs');

export async function connectToDatabase() {
    const collections = [ 'a', 'b', 'c' ];
    
    
    const client = new mongoDB.MongoClient("mongodb://127.0.0.1:27017/");

    await client.connect();

    const databasesList = await client.db().admin().listDatabases();
    console.log("Databases:");

    const poDb = _.find(databasesList.databases, function(db : any) { return db.name === 'mytestdb'; });
    if (poDb === undefined) {
        console.log('mytestdb database not found');
        await client.db("mytestdb").createCollection("testcoll");
    } else {
        console.log(` - ${poDb.name}`);
    }
    
    const dbObject = client.db('mytestdb');    

    _.forEach(collections,async function(value : string) {     
        const collObject = await getCollectionObject(dbObject, value);

        const datafile = './initfiles/' + value + '.json';
        //console.log(`datafile ${datafile}`);

        const data= fs.readFileSync(datafile, 'utf8');                
        const inputData = mongoDB.BSON.deserialize(data);                                                                    
        await collObject.insertMany(_.toArray(inputData));
        console.log(`loaded data into collection ${value}`);    
    });
}

async function getCollectionObject(dbObject: any, collectionName: string)  {

    const collObject = dbObject.collection(collectionName);
    if (collObject === undefined || collObject.collectionName !== collectionName) {
        console.log(`Create Collection - ${collectionName}`);
        return await dbObject.createCollection(collectionName);
    } else {
        console.log(`Collection exists - ${collObject.collectionName}`);
        return collObject;
    }
}

it looks like until a record is added, it doesn’t show up in the list whereas that is not the case when you do it from the compass.

Hoping an expert can answer why that is the case.