Expand drop collection code... needs more work

This commit is contained in:
Fred Boniface 2023-01-10 21:04:49 +00:00
parent 538325cada
commit 1c269571b7

View File

@ -14,10 +14,16 @@ const db = client.db(dbName);
async function dropCollection(coll){
log.out(`DbAccess.dropCollection: checking if collection exists: ${coll}`)
//Some Code Here
//Some Code Here:
await client.connect();
var cols = await db.listCollections().toArray()
log.out(`dbAccess.dropCollection: Existing collections: ${JSON.stringify(cols)}`)
// If (any object in the Array contains name:{coll} then exsists. If not doesn't exist.)
// If Collection Exists:
log.out(`DbAccess.dropCollection: dropping collection: ${coll}`)
await client.connect();
db.dropCollection(coll);
log.out(`DbAccess.dropCollection: dropped collection: ${coll}`)
// Else Do Nothing