Skip to content

Commit

Permalink
fix: Restore $all operator (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
speedytwenty authored Mar 12, 2024
1 parent a12988a commit 89bd4f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,20 @@ type AddToSetOperator = {
*/
const $addToSet = se('$addToSet');

type AllOperator = {
$all: ArrayExpression,
}

/**
* Selects documents where the value of a field is an array that contains all
* the specified elements.
* @function
* @category Other Operators
* @param {...Expression[]} expressions Match expression.
* @returns {AllOperator} The compiled $all operator.
*/
const $all = (...expressions: Expression[] ) => ({ $all: [...expressions ]});

type AllElementsTrueOperator = {
$allElementsTrue: Array<Expression>,
};
Expand Down Expand Up @@ -3532,6 +3546,8 @@ export = {
addFields: $addFields,
$addToSet,
addToSet: $addToSet,
$all,
all: $all,
$allElementsTrue,
allElementsTrue: $allElementsTrue,
$and,
Expand Down
10 changes: 10 additions & 0 deletions pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@ describe('aggregation', () => {
expect($.addToSet('$myVar')).toEqual({ $addToSet: '$myVar' });
});
});
describe('$all', () => {
it('exports expected vars', () => {
expect($.all).toBeDefined();
expect($.$all).toBeDefined();
expect($.all).toStrictEqual($.$all);
});
it('returns expected result', () => {
expect($.all(1, 2, 3)).toEqual({ $all: [1, 2, 3] });
});
});
describe('$allElementsTrue', () => {
it('exports expected vars', () => {
expect($.allElementsTrue).toBeDefined();
Expand Down

0 comments on commit 89bd4f1

Please sign in to comment.