Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit 08b1d14

Browse files
committed
feat(filter): Adds $nor operator.
1 parent 423fac1 commit 08b1d14

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

docs/filter.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Operator | Description
66
--- | ---
77
[$and](https://docs.mongodb.com/manual/reference/operator/query/and/#op._S_and) | Includes entities where all of the specified filters are true.
88
[$or](https://docs.mongodb.com/manual/reference/operator/query/or/#op._S_or) | Includes entities where some of the specified filters are true.
9+
[$nor](https://docs.mongodb.com/manual/reference/operator/query/nor/#op._S_nor) | Includes entities where some of the specified filters are false.
910
[$not](https://docs.mongodb.com/manual/reference/operator/query/no/#op._S_no) | Includes entities where a specified filter is not true.
1011
[$eq](https://docs.mongodb.com/manual/reference/operator/query/eq/#op._S_eq) | Includes entities where the value of a given property is equal to the specified value.
1112
[$ne](https://docs.mongodb.com/manual/reference/operator/query/ne/#op._S_ne) | Includes entities where the value of a given property is not equal to the specified value.
@@ -49,6 +50,14 @@ The filter below is comprehensive example using all of the operators.
4950
}
5051
}
5152
]
53+
},
54+
,
55+
{
56+
"$nor": [
57+
{
58+
"stringProp4": "string value 6"
59+
}
60+
]
5261
}
5362
]
5463
}

src/tests/utils/filterTest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export default (opts: Opts) => {
7272
await opts.assertFirstEntityFilter({ $or: [{ stringProp: 'a' }, { numberProp: 1 }] });
7373
});
7474

75+
it('should filter correctly when using $nor operator', async () => {
76+
await createTestEntities();
77+
await opts.assertFirstEntityFilter({ $nor: [{ stringProp: 'b' }, { numberProp: 2 }] });
78+
});
79+
7580
it('should filter correctly when using $not operator', async () => {
7681
await createTestEntities();
7782
await opts.assertFirstEntityFilter({ stringProp: { $not: { $eq: 'b' } } });

src/types/Filter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ export interface OrFilter<Entity> {
2424
readonly $or: Filter<Entity>[];
2525
}
2626

27+
export interface NorFilter<Entity> {
28+
readonly $nor: Filter<Entity>[];
29+
}
30+
2731
export type Filter<Entity> = (
2832
EntityFilter<Entity> |
2933
AndFilter<Entity> |
30-
OrFilter<Entity>
34+
OrFilter<Entity> |
35+
NorFilter<Entity>
3136
);
3237

3338
export default Filter;

src/utils/createPaginationFilter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as atob from 'atob';
22
import { get, mapValues } from 'lodash';
33
// tslint:disable-next-line:no-unused
4-
import Filter, { AndFilter, NotFilter, OrFilter } from '../../types/Filter';
4+
import Filter, { AndFilter, NorFilter, NotFilter, OrFilter } from '../../types/Filter';
55
import Pagination from '../../types/Pagination';
66
import Sort from '../../types/Sort';
77

0 commit comments

Comments
 (0)