Skip to content

Commit

Permalink
Fixed #87 and added test for $or opeartor (#88)
Browse files Browse the repository at this point in the history
* Fixed #87 and added test for  opeartor
* Also updated $not operator to FilterType<T>
  • Loading branch information
lazandrei19 authored Aug 3, 2020
1 parent 0c1d4ae commit 5ff7075
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ test("testInsertMany", async () => {
assertEquals(insertIds.length, 2);
});

test("testFindOr", async () => {
const db = getClient().database("test");
const users = db.collection<IUser>("mongo_test_users");
const user1 = await users.find({
$or: [{
password: "pass1",
}, {
password: "pass2",
}],
});

assert(user1 instanceof Array);
assertEquals(user1.length, 3);
});

test("testFind", async () => {
const db = getClient().database("test");
const users = db.collection("mongo_test_users");
Expand Down
8 changes: 4 additions & 4 deletions ts/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export type QuerySelector<T> = {
$ne?: T;
$nin?: T[];
// Logical
$not?: T extends string ? (QuerySelector<T> | RegExp) : QuerySelector<T>;
$not?: T extends string ? (QuerySelector<T> | RegExp) : FilterType<T>;
/** https://docs.mongodb.com/manual/reference/operator/query/and/#op._S_and */
$and?: T extends string ? (QuerySelector<T> | RegExp) : QuerySelector<T>;
$and?: T extends string ? (QuerySelector<T> | RegExp) : FilterType<T>[];
/** https://docs.mongodb.com/manual/reference/operator/query/nor/#op._S_nor */
$nor?: T extends string ? (QuerySelector<T> | RegExp) : QuerySelector<T>;
$nor?: T extends string ? (QuerySelector<T> | RegExp) : FilterType<T>[];
/** https://docs.mongodb.com/manual/reference/operator/query/or/#op._S_or */
$or?: T extends string ? (QuerySelector<T> | RegExp) : QuerySelector<T>;
$or?: T extends string ? (QuerySelector<T> | RegExp) : FilterType<T>[];

/** https://docs.mongodb.com/manual/reference/operator/query/comment/#op._S_comment */
$comment?: string;
Expand Down

0 comments on commit 5ff7075

Please sign in to comment.