cypress-mongodb
Version:
Cypress MongoDB plugin
38 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateOne = updateOne;
exports.updateMany = updateMany;
const mongodb_1 = require("mongodb");
const bson_1 = require("bson");
async function updateOne(args) {
args.filter = (0, bson_1.deserialize)(Buffer.from(args.filter));
args.document = (0, bson_1.deserialize)(Buffer.from(args.document));
return mongodb_1.MongoClient.connect(args.uri).then(async (client) => {
try {
const result = await client
.db(args.database)
.collection(args.collection)
.updateOne(args.filter, args.document, args.options);
return result ? (0, bson_1.serialize)(result) : null;
}
finally {
await client.close();
}
});
}
async function updateMany(args) {
args.filter = (0, bson_1.deserialize)(Buffer.from(args.filter));
args.document = (0, bson_1.deserialize)(Buffer.from(args.document));
return mongodb_1.MongoClient.connect(args.uri).then(async (client) => {
try {
const database = client.db(args.database);
const collection = database.collection(args.collection);
const result = await collection.updateMany(args.filter, args.document, args.options);
return result ? (0, bson_1.serialize)(result) : null;
}
finally {
await client.close();
}
});
}
//# sourceMappingURL=update.js.map