Dropping All Collections, drops database | Nodejs Driver

We are trying to delete all the collections using latest mongodb nodejs driver v 3.6. It deletes the collections but at the same time drops the database as well. Is this expected behaviour? Here is the code.

const mongoClient = require("mongodb").MongoClient;

let client;

async function connect() {
  if (!client) {
    client = await mongoClient.connect("mongodb://localhost:27017/somedb", {"useUnifiedTopology": true});
  }
  const db = client.db();

  return db;
}

const dbCollections = ["A", "b", "c", "d", "e", "f"];

async function createCollections() {
  const db = await connect();

  return Promise.all(
    dbCollections
      .map(collection => db.createCollection(collection))
  );
}


async function dropCollections() {
  const db = await connect();
  for (const collection of dbCollections) {
    const resposne = await db.collection(collection).drop();
    console.log(`deleted ${collection}`, resposne);
  }
}

createCollections().then(() => dropCollections());

Hello @Ashish_Modi, welcome to the MongoDB community forum!

This seems to be the behavior with NodeJS driver (I got similar result with my own code). This also turned out true with mongo shell.

Thanks @Prasad_Saya for your reply. Can I ask which version of mongodb are you using?

My MongoDB version was 4.2.8 and NodeJS driver’s was v3.6.