Skip to content

effect-mongodb is the core package that provides effectful APIs to work with MongoDB.

@effect-mongodb/services is the package that provides Effect services for effect-mongodb.

Docs for Effect v4 (>= 0.8). For Effect v3 see 0.7.x

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.DateFromString
})
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)

More from doubleloop

oxlint-plugin-effect: a set of Oxlint rules for Effect, by the same authors.

Released under the MIT License.