UNPKG

2.12 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.aggregate = exports.remove = exports.find = exports.Query = exports.Aggregator = void 0;
4// loads basic operators
5require("./init/basic");
6var aggregator_1 = require("./aggregator");
7var query_1 = require("./query");
8var aggregator_2 = require("./aggregator");
9Object.defineProperty(exports, "Aggregator", { enumerable: true, get: function () { return aggregator_2.Aggregator; } });
10var query_2 = require("./query");
11Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_2.Query; } });
12/**
13 * Performs a query on a collection and returns a cursor object.
14 * Shorthand for `Query(criteria).find(collection, projection)`
15 *
16 * @param collection Array of objects
17 * @param criteria Query criteria
18 * @param projection Projection criteria
19 * @param options
20 * @returns {Cursor} A cursor of results
21 */
22function find(collection, criteria, projection, options) {
23 return new query_1.Query(criteria, options).find(collection, projection);
24}
25exports.find = find;
26/**
27 * Returns a new array without objects which match the criteria
28 *
29 * @param collection Array of objects
30 * @param criteria Query criteria of objects to remove
31 * @param options
32 * @returns {Array} New filtered array
33 */
34function remove(collection, criteria, options) {
35 return new query_1.Query(criteria, options).remove(collection);
36}
37exports.remove = remove;
38/**
39 * Return the result collection after running the aggregation pipeline for the given collection.
40 * Shorthand for `(new Aggregator(pipeline, options)).run(collection)`
41 *
42 * @param collection Collection or stream of objects
43 * @param pipeline The pipeline operators to use
44 * @param options
45 * @returns {Array} New array of results
46 */
47function aggregate(collection, pipeline, options) {
48 return new aggregator_1.Aggregator(pipeline, options).run(collection);
49}
50exports.aggregate = aggregate;
51// default interface
52exports.default = {
53 Aggregator: aggregator_1.Aggregator,
54 Query: query_1.Query,
55 aggregate: aggregate,
56 find: find,
57 remove: remove,
58};