cypress-mongodb
Version:
Cypress MongoDB plugin
58 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCollection = createCollection;
exports.dropCollection = dropCollection;
const mongodb_1 = require("mongodb");
async function createCollection(args) {
const client = await mongodb_1.MongoClient.connect(args.uri);
const database = client.db(args.database);
const failSilently = args.options?.failSilently;
if (args.options) {
delete args.options.database;
delete args.options.failSilently;
}
try {
const result = await database.createCollection(args.collection, args.options);
if (result) {
return 'Collection created';
}
else {
return 'Error';
}
}
catch (error) {
if (failSilently)
return error;
else
throw error;
}
finally {
await client.close();
}
}
async function dropCollection(args) {
const client = await mongodb_1.MongoClient.connect(args.uri);
const failSilently = args.options?.failSilently;
if (args.options)
delete args.options.failSilently;
try {
const database = client.db(args.database);
const result = await database.dropCollection(args.collection, args.options);
if (result) {
return 'Collection dropped';
}
else {
return 'Error';
}
}
catch (error) {
if (failSilently)
return error;
else
throw error;
}
finally {
await client.close();
}
}
//# sourceMappingURL=collection.js.map