Registry / database / yammy
library2.1.0jsnpmunverified

Yammy is a MongoDB migration library (v2.1.0) designed for programmatic use as a module, unlike CLI-focused alternatives. It supports multiple databases, backward compatibility with migrate-mongo, and uses transactions by default for data integrity. Requires Node.js >=8.0.0 and MongoDB >=2.6 (or >=4.0/4.2 for transactions). Stable release with TypeScript type definitions included, released under MIT license.

npm install yammy
INSTALL
IMPORT
SIG · YAMMY
Y
yammy
databasejavascriptv2.1.0
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.

Migrate
import { Migrate } from 'yammy'
const Migrate = require('yammy')
ESM import for TypeScript/ES modules; CommonJS users can use require but note the named export.
Migration
import type { Migration } from 'yammy'
import { Migration } from 'yammy'
Type-only import for defining migration structure; not a runtime value.
YammyOptions
import type { YammyOptions } from 'yammy'
import { YammyOptions } from 'yammy'
Type-only import for constructor options interface.

Initialize Migrate instance, list pending migrations, and apply them. Includes example migration file with up/down functions.

import { Migrate } from 'yammy'; const migrate = new Migrate( { uri: process.env.MONGO_URI ?? 'mongodb://localhost:27017', options: { useNewUrlParser: true, useUnifiedTopology: true } }, { autoClose: true, dir: './migrations' } ); // List pending migrations migrate.pending() .then((migrations) => { console.log('Pending:', migrations); // Run all pending return migrate.up(); }) .then(() => console.log('Migrations applied successfully')) .catch(err => console.error(err)); export const up = async (db, session) => { await db.collection('mycollection').createIndex({ email: 1 }, { unique: true, session }); }; export const down = async (db, session) => { await db.collection('mycollection').dropIndex('email_1', { session }); }; export const db = 'mydb';
Debug
Known issues
breakingIn version 2.x, the Migrate constructor signature changed. Options object now takes two arguments: dbConfig and globalOptions.
fix
Update constructor to `new Migrate({ uri, options }, { autoClose, dir })`
affects: >=2.0.0
gotchaMigrations using transactions require MongoDB replica set (>=4.0) or sharded cluster (>=4.2). Default migrations will fail if not supported.
fix
Ensure MongoDB is configured for transactions or set `useTransactions: false` in options.
affects: >=1.0.0
gotchaThe migration file must export a `db` string property to specify target database, otherwise migrations will apply to all databases.
fix
Add `exports.db = 'your_database_name';` to each migration file.
affects: >=1.0.0
deprecatedThe CLI usage via `npx yammy` is deprecated in favor of programmatic API. CLI may be removed in future releases.
fix
Use the Migrate class in your application code instead of CLI.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Migrate is not a constructor
Improper import/require style: using default import instead of named import.
fix
Use `import { Migrate } from 'yammy'` (ESM) or `const { Migrate } = require('yammy')` (CommonJS).
MongoError: Transaction numbers are only allowed on a replica set member or mongos
Trying to use transactions on a standalone MongoDB instance.
fix
Either switch to a replica set or set `useTransactions: false` in Migrate options.
Cannot find module 'yammy'
Package not installed.
fix
Run `npm install yammy` in your project directory.
Error: No database provided in migration file
Migration file missing `exports.db` property.
fix
Add `exports.db = 'myDatabaseName';` to the migration file.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency for database operations; must be installed separately.
Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources
packageyammy
yammy — npm install yammy · libregistry