Skip to content

Commit a8530e7

Browse files
committed
DocumentCollection+Collection: add dropIndex
1 parent 6cc9c61 commit a8530e7

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect-mongodb": patch
3+
---
4+
5+
Add dropIndex function in Collection and DocumentCollection

packages/effect-mongodb/src/Collection.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
DeleteResult,
1717
Document,
1818
DropCollectionOptions,
19+
DropIndexesOptions,
1920
FindOptions as MongoFindOptions,
2021
IndexDescription,
2122
IndexSpecification,
@@ -353,6 +354,32 @@ export const createIndex: {
353354
)
354355
)
355356

357+
export const dropIndex: {
358+
(
359+
indexName: string,
360+
options?: DropIndexesOptions
361+
): <A extends Document, I extends Document, R>(
362+
collection: Collection<A, I, R>
363+
) => Effect.Effect<void, MongoError.MongoError, R>
364+
<A extends Document, I extends Document, R>(
365+
collection: Collection<A, I, R>,
366+
indexName: string,
367+
options?: DropIndexesOptions
368+
): Effect.Effect<void, MongoError.MongoError, R>
369+
} = F.dual(
370+
(args) => isCollection(args[0]),
371+
<A extends Document, I extends Document, R>(
372+
collection: Collection<A, I, R>,
373+
indexName: string,
374+
options?: DropIndexesOptions
375+
): Effect.Effect<void, MongoError.MongoError, R> =>
376+
F.pipe(
377+
Effect.promise(() => collection.collection.dropIndex(indexName, options)),
378+
Effect.asVoid,
379+
Effect.catchAllDefect(MongoError.mongoErrorDie<void>("dropIndex error"))
380+
)
381+
)
382+
356383
export const aggregate: {
357384
<B extends Document, BI extends Document, BR>(
358385
pipeline: Array<Document>,

packages/effect-mongodb/src/DocumentCollection.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
DeleteResult,
1616
Document,
1717
DropCollectionOptions,
18+
DropIndexesOptions,
1819
Filter,
1920
FindOptions,
2021
IndexDescription,
@@ -324,6 +325,29 @@ export const createIndex: {
324325
)
325326
)
326327

328+
export const dropIndex: {
329+
(
330+
indexName: string,
331+
options?: DropIndexesOptions
332+
): (collection: DocumentCollection) => Effect.Effect<Document, MongoError.MongoError>
333+
(
334+
collection: DocumentCollection,
335+
indexName: string,
336+
options?: DropIndexesOptions
337+
): Effect.Effect<Document, MongoError.MongoError>
338+
} = F.dual(
339+
(args) => isDocumentCollection(args[0]),
340+
(
341+
collection: DocumentCollection,
342+
indexName: string,
343+
options?: DropIndexesOptions
344+
): Effect.Effect<Document, MongoError.MongoError> =>
345+
F.pipe(
346+
Effect.promise(() => collection.collection.dropIndex(indexName, options)),
347+
Effect.catchAllDefect(MongoError.mongoErrorDie<Document>("dropIndex error"))
348+
)
349+
)
350+
327351
export const aggregate: {
328352
(
329353
pipeline?: Array<Document>,

0 commit comments

Comments
 (0)