diff --git a/.changeset/shiny-tables-decide.md b/.changeset/shiny-tables-decide.md new file mode 100644 index 0000000..ff363ea --- /dev/null +++ b/.changeset/shiny-tables-decide.md @@ -0,0 +1,6 @@ +--- +"effect-mongodb": patch +--- + +Use Filter type in FindCursor and DocumentFindCursor filter function. +Add optional filter parameter to find functions in Collection and DocumentCollection diff --git a/packages/effect-mongodb/src/Collection.ts b/packages/effect-mongodb/src/Collection.ts index e517421..1024e45 100644 --- a/packages/effect-mongodb/src/Collection.ts +++ b/packages/effect-mongodb/src/Collection.ts @@ -40,21 +40,24 @@ export class Collection e export type FindOptions = Omit export const find: { - ( + ( + filter?: Filter, options?: FindOptions - ): (collection: Collection) => FindCursor.FindCursor + ): (collection: Collection) => FindCursor.FindCursor ( collection: Collection, + filter?: Filter, options?: FindOptions ): FindCursor.FindCursor } = F.dual( (args) => isCollection(args[0]), ( collection: Collection, + filter?: Filter, options?: FindOptions ): FindCursor.FindCursor => new FindCursor.FindCursor({ - cursor: collection.collection.find({}, options), + cursor: collection.collection.find(filter ?? {}, options), schema: collection.schema }) ) diff --git a/packages/effect-mongodb/src/DocumentCollection.ts b/packages/effect-mongodb/src/DocumentCollection.ts index e0e6f19..66a12aa 100644 --- a/packages/effect-mongodb/src/DocumentCollection.ts +++ b/packages/effect-mongodb/src/DocumentCollection.ts @@ -39,17 +39,21 @@ export class DocumentCollection extends Data.TaggedClass("DocumentCollection")<{ } export const find: { - (options?: FindOptions): (collection: DocumentCollection) => DocumentFindCursor.DocumentFindCursor + ( + filter?: Filter, + options?: FindOptions + ): (collection: DocumentCollection) => DocumentFindCursor.DocumentFindCursor ( collection: DocumentCollection, + filter?: Filter, options?: FindOptions ): DocumentFindCursor.DocumentFindCursor } = F.dual( (args) => isDocumentCollection(args[0]), - (collection: DocumentCollection, options?: FindOptions) => + (collection: DocumentCollection, filter?: Filter, options?: FindOptions) => new DocumentFindCursor.DocumentFindCursor( { - cursor: collection.collection.find({}, options) + cursor: collection.collection.find(filter ?? {}, options) } ) )