UNPKG

cypress-mongodb

Version:
36 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.insertOne = insertOne; exports.insertMany = insertMany; const mongodb_1 = require("mongodb"); const bson_1 = require("bson"); async function insertOne(args) { args.document = (0, bson_1.deserialize)(Buffer.from(args.document)); return mongodb_1.MongoClient.connect(args.uri).then(async (client) => { try { const collection = client .db(args.database) .collection(args.collection); const result = await collection.insertOne(args.document, args.options); return result.insertedId; } finally { await client.close(); } }); } async function insertMany(args) { args.documents = (0, bson_1.deserialize)(Buffer.from(args.documents)); args.documents = Object.values(args.documents); return mongodb_1.MongoClient.connect(args.uri).then(async (client) => { try { const collection = client.db(args.database).collection(args.collection); const result = await collection.insertMany(args.documents, args.options); return result.insertedIds; } finally { await client.close(); } }); } //# sourceMappingURL=insert.js.map