MCPcopy
hub / github.com/mongodb/node-mongodb-native / setupDatabase

Function setupDatabase

test/integration/shared.js:89–108  ·  test/integration/shared.js::setupDatabase
(configuration, dbsToClean)

Source from the content-addressed store, hash-verified

87}
88
89async function setupDatabase(configuration, dbsToClean) {
90 dbsToClean = Array.isArray(dbsToClean) ? dbsToClean : [];
91 const configDbName = configuration.db;
92
93 dbsToClean.push(configDbName);
94
95 const client = configuration.newClient();
96 try {
97 for (const dbName of dbsToClean) {
98 const db = await client.db(dbName);
99 for await (const { name } of db.listCollections({}, { nameOnly: true })) {
100 const collection = db.collection(name);
101 await collection.deleteMany({}).catch(() => null);
102 await collection.drop().catch(() => null);
103 }
104 }
105 } finally {
106 await client.close();
107 }
108}
109
110/**
111 * Safely perform a test with an arbitrary cursor.

Calls 8

listCollectionsMethod · 0.80
deleteManyMethod · 0.80
collectionMethod · 0.65
pushMethod · 0.45
newClientMethod · 0.45
dbMethod · 0.45
dropMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected