Registry / database / fawn
library2.1.5jsnpmunverified

Promise-based library for implementing transactions in MongoDB using a two-phase commit approach. Version 2.1.5 is the latest stable release. It provides a task-based API for defining a series of CRUD operations that either all succeed or are rolled back entirely. Unlike MongoDB's native transactions (which require replica sets), Fawn works with standalone MongoDB instances. It supports both native MongoDB driver and Mongoose, and includes GridFS file support. The library has not seen updates since 2019 and the repository is archived.

npm install fawn
INSTALL
IMPORT
SIG · FAWN
F
fawn
databasejavascriptv2.1.5
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.

Fawn
const Fawn = require('fawn');
import Fawn from 'fawn';
Fawn does not ship ESM; only CommonJS is supported.
Task
const task = Fawn.Task();
Task is a static method on Fawn, not an exported class.
Roller
const roller = Fawn.Roller();
Roller is a static method to rollback incomplete tasks on server start.

Sets up Fawn with Mongoose connection, creates a task with two updates, and runs it with rollback on failure.

const Fawn = require('fawn'); const mongoose = require('mongoose'); mongoose.connect('mongodb://127.0.0.1:27017/testDB', { useNewUrlParser: true, useUnifiedTopology: true }); Fawn.init(mongoose); const task = Fawn.Task(); task.update('accounts', { name: 'John' }, { $inc: { balance: -20 } }) .update('accounts', { name: 'Jane' }, { $inc: { balance: 20 } }) .run() .then(results => { console.log('Transaction succeeded'); }) .catch(err => { console.error('Transaction rolled back', err); });
Debug
Known issues
breakingFawn.init() must be called before any task creation
fix
Call Fawn.init(connection) at the start of your application.
affects: >=2.0.0
gotchaFawn does not work with MongoDB replica sets; it implements its own two-phase commit
fix
Use native MongoDB transactions (require replica sets) or keep using Fawn with standalone MongoDB.
affects: all
gotchaFawn creates a collection named 'fawn_sequences' in the database to manage transaction state
fix
Do not manually modify or delete the 'fawn_sequences' collection.
affects: all
gettingFawn does not support ESM imports; only CommonJS require()
fix
Use const Fawn = require('fawn'); instead of import.
affects: all
Errors
Common errors & fixes
Fawn is not defined
Missing require('fawn') or incorrect import
fix
Add const Fawn = require('fawn'); at the top of your file.
Fawn.init is not a function
Fawn is imported incorrectly (ESM vs CJS) or version is too old
fix
Ensure you are using require('fawn') and version >=2.0.0.
Cannot read property 'update' of undefined
Fawn.Task() not called correctly or Fawn.init() not yet called
fix
Call Fawn.init(connection) before Fawn.Task(). Then const task = Fawn.Task();
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies
mongodboptionalUsed for native MongoDB driver operations when not using Mongoose
mongooseoptionalUsed when initializing with a Mongoose connection
Agent activity
4 hits · last 30 days
node
4
Resources
packagefawn
fawn — npm install fawn · libregistry