Skip to content

Commit 6f0a8d4

Browse files
committed
DocumentCollection+Collection: add optional filter parameter to find function (close #4)
1 parent 74e18f7 commit 6f0a8d4

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

.changeset/shiny-tables-decide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"effect-mongodb": patch
3+
---
4+
5+
Use Filter type in FindCursor and DocumentFindCursor filter function.
6+
Add optional filter parameter to find functions in Collection and DocumentCollection

packages/effect-mongodb/src/Collection.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,24 @@ export class Collection<A extends Document, I extends Document = A, R = never> e
4040
export type FindOptions = Omit<MongoFindOptions, "projection">
4141

4242
export const find: {
43-
(
43+
<I extends Document>(
44+
filter?: Filter<I>,
4445
options?: FindOptions
45-
): <A extends Document, I extends Document, R>(collection: Collection<A, I, R>) => FindCursor.FindCursor<A, I, R>
46+
): <A extends Document, R>(collection: Collection<A, I, R>) => FindCursor.FindCursor<A, I, R>
4647
<A extends Document, I extends Document, R>(
4748
collection: Collection<A, I, R>,
49+
filter?: Filter<I>,
4850
options?: FindOptions
4951
): FindCursor.FindCursor<A, I, R>
5052
} = F.dual(
5153
(args) => isCollection(args[0]),
5254
<A extends Document, I extends Document, R>(
5355
collection: Collection<A, I, R>,
56+
filter?: Filter<I>,
5457
options?: FindOptions
5558
): FindCursor.FindCursor<A, I, R> =>
5659
new FindCursor.FindCursor<A, I, R>({
57-
cursor: collection.collection.find({}, options),
60+
cursor: collection.collection.find(filter ?? {}, options),
5861
schema: collection.schema
5962
})
6063
)

packages/effect-mongodb/src/DocumentCollection.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,21 @@ export class DocumentCollection extends Data.TaggedClass("DocumentCollection")<{
3939
}
4040

4141
export const find: {
42-
(options?: FindOptions): (collection: DocumentCollection) => DocumentFindCursor.DocumentFindCursor
42+
(
43+
filter?: Filter<Document>,
44+
options?: FindOptions
45+
): (collection: DocumentCollection) => DocumentFindCursor.DocumentFindCursor
4346
(
4447
collection: DocumentCollection,
48+
filter?: Filter<Document>,
4549
options?: FindOptions
4650
): DocumentFindCursor.DocumentFindCursor
4751
} = F.dual(
4852
(args) => isDocumentCollection(args[0]),
49-
(collection: DocumentCollection, options?: FindOptions) =>
53+
(collection: DocumentCollection, filter?: Filter<Document>, options?: FindOptions) =>
5054
new DocumentFindCursor.DocumentFindCursor(
5155
{
52-
cursor: collection.collection.find({}, options)
56+
cursor: collection.collection.find(filter ?? {}, options)
5357
}
5458
)
5559
)

0 commit comments

Comments
 (0)