UNPKG

cypress-mongodb

Version:
25 lines 870 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.aggregate = aggregate; const mongodb_1 = require("mongodb"); const bson_1 = require("bson"); async function aggregate(args) { const deserializedPipeline = (0, bson_1.deserialize)(Buffer.from(args.pipeline)); args.pipeline = Object.values(deserializedPipeline); const client = await mongodb_1.MongoClient.connect(args.uri); try { const result = await client .db(args.database) .collection(args.collection) .aggregate(args.pipeline, args.options) .toArray(); return (0, bson_1.serialize)(Object.fromEntries(result.entries())); } catch (err) { throw new Error('Error connecting: ' + err.stack); } finally { await client.close(); } } //# sourceMappingURL=aggregation.js.map