Registry / database / effect-mongodb

effect-mongodb

JSON →
library0.4.1jsnpmunverified

A MongoDB toolkit for Effect (v0.4.1), providing both Document-based (no runtime validation) and Schema-based (runtime validation via Effect Schema) APIs that mirror the native MongoDB driver. It wraps MongoDB operations in Effect effects for composable, typed error handling with MongoError. Requires peer dependencies effect ^3.10.14 and mongodb ^6.9.0. Supports cursors via toArray (eager) and toStream (streaming).

npm install effect-mongodb
INSTALL
IMPORT
SIG · EFFECT-MONGODB
E
effect-mongodb
databasejavascriptv0.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MongoClient
import { MongoClient } from 'effect-mongodb'
import { MongoClient } from 'mongodb'
Use effect-mongodb's MongoClient, not the raw mongodb driver, to get Effect integration.
Collection
import { Collection } from 'effect-mongodb'
import { Collection } from 'mongodb'
Collection from effect-mongodb is Schema-based and returns Effect types.
Db
import { Db } from 'effect-mongodb'
import { Db } from 'mongodb'
Db is used to create Schema-based collections via Db.collection() with a Schema.
DocumentCollection
import { DocumentCollection } from 'effect-mongodb'
Document-prefixed modules skip runtime validation; use for non-schema codebases.

Connects to MongoDB, copies documents from one collection to another using Schema-based Collection and FindCursor, with scoped lifecycle management.

import { Effect, Schema } from 'effect' import { Collection, Db, FindCursor, MongoClient } from 'effect-mongodb' const Person = Schema.Struct({ name: Schema.String, age: Schema.Number, birthday: Schema.Date }) const program = Effect.gen(function*() { const client = yield* MongoClient.connectScoped('mongodb://localhost:27017') const db = MongoClient.db(client, 'source-db') const sourceCollection = Db.collection(db, 'source', Person) const destinationCollection = Db.collection(db, 'destination', Person) const items = yield* Collection.find(sourceCollection).pipe(FindCursor.toArray) yield* Collection.insertMany(destinationCollection, items) }) await program.pipe(Effect.scoped, Effect.runPromise)
Debug
Known issues
breakingPeer dependencies effect ^3.10.14 and mongodb ^6.9.0 are required; using older versions may cause type or runtime errors.
fix
Update effect to >=3.10.14 and mongodb to >=6.9.0.
affects: >=0.4.0
gotchaMongoClient.connectScoped creates a scoped connection that must be used within Effect.scoped; forgetting to wrap with Effect.scoped will result in unhandled scope errors.
fix
Wrap the program with Effect.scoped before running.
affects: >=0.1.0
gotchaSchema-based Collection operations expect a Schema; passing raw Document types will cause validation failures at runtime.
fix
Use DocumentCollection for unvalidated operations.
affects: >=0.1.0
gotchaOption is used instead of null/undefined in API responses; code that checks for null will break.
fix
Use Option.isSome() and Option.isNone() from 'effect/Option'.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: (0 , effect_mongodb_1.MongoClient) is not a function
Importing from 'mongodb' instead of 'effect-mongodb'
fix
Use import { MongoClient } from 'effect-mongodb'.
Cannot find module 'effect-mongodb' or its corresponding type declarations.
Missing installation of effect-mongodb
fix
Run npm install effect-mongodb effect mongodb.
Error: Effect.runPromise is not a function
Calling runPromise without importing Effect from 'effect'
fix
Import { Effect } from 'effect' and call Effect.runPromise.
Upgrade
Version history
0.4.1latest on npm
Audit
Dependencies
effectrequiredCore Effect library for effects, streams, and schema
mongodbrequiredOfficial MongoDB Node.js driver for database operations
Agent activity
8 hits · last 30 days
node
6
Resources
effect-mongodb — npm install effect-mongodb · libregistry