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());