From 5ff7075182095feb6de71eb417d1b730577be8ca Mon Sep 17 00:00:00 2001 From: Andrei Lazarescu Date: Mon, 3 Aug 2020 03:40:14 +0300 Subject: [PATCH] Fixed #87 and added test for $or opeartor (#88) * Fixed #87 and added test for opeartor * Also updated $not operator to FilterType --- test.ts | 15 +++++++++++++++ ts/collection.ts | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/test.ts b/test.ts index 1a4f0516..380d179d 100644 --- a/test.ts +++ b/test.ts @@ -158,6 +158,21 @@ test("testInsertMany", async () => { assertEquals(insertIds.length, 2); }); +test("testFindOr", async () => { + const db = getClient().database("test"); + const users = db.collection("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"); diff --git a/ts/collection.ts b/ts/collection.ts index 8ca10e3d..c4eb406d 100644 --- a/ts/collection.ts +++ b/ts/collection.ts @@ -67,13 +67,13 @@ export type QuerySelector = { $ne?: T; $nin?: T[]; // Logical - $not?: T extends string ? (QuerySelector | RegExp) : QuerySelector; + $not?: T extends string ? (QuerySelector | RegExp) : FilterType; /** https://docs.mongodb.com/manual/reference/operator/query/and/#op._S_and */ - $and?: T extends string ? (QuerySelector | RegExp) : QuerySelector; + $and?: T extends string ? (QuerySelector | RegExp) : FilterType[]; /** https://docs.mongodb.com/manual/reference/operator/query/nor/#op._S_nor */ - $nor?: T extends string ? (QuerySelector | RegExp) : QuerySelector; + $nor?: T extends string ? (QuerySelector | RegExp) : FilterType[]; /** https://docs.mongodb.com/manual/reference/operator/query/or/#op._S_or */ - $or?: T extends string ? (QuerySelector | RegExp) : QuerySelector; + $or?: T extends string ? (QuerySelector | RegExp) : FilterType[]; /** https://docs.mongodb.com/manual/reference/operator/query/comment/#op._S_comment */ $comment?: string;