East MongoDB Adapter

1.0.0 · abandoned · verified Wed Apr 22

east-mongo is an adapter for the `east` Node.js database migration tool, specifically designed for MongoDB. It leverages the official `mongodb` native driver (peer dependency on versions 2.x.x or 3.x.x) to manage schema changes and data migrations. When migrations are executed, their names are recorded in a `_migrations` collection within the target database. The adapter provides helper functions like `dropIndexIfExists` and includes template options for promises-based or async/await migrations. This package, currently at version 1.0.0, appears to be abandoned, with no releases or significant activity since 2017, meaning it is not actively maintained and may have unpatched vulnerabilities or compatibility issues with modern MongoDB versions or Node.js runtimes. Its primary function is to provide the `db` instance from the native driver to migration scripts.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `east-mongo` in an `.eastrc` file and provides a basic migration example using async/await functions for creating a collection, adding an index, inserting data, and a corresponding rollback function.

/* .eastrc file */
module.exports = {
	"adapter": "east-mongo",
	"url": "mongodb://localhost:27017/my_database",
	"options": {
		"server": {
			"socketOptions": {
				"socketTimeoutMS": 3600000
			}
		}
	}
};

/* Example migration file (e.g., 20230101000000-initial-setup.js) */
exports.tags = [];

exports.migrate = async function(params) {
	const { db, dropIndexIfExists } = params;

	// Example: Create a collection and an index
	await db.collection('users').createIndex({ email: 1 }, { unique: true });
	console.log('Created unique index on users.email');

	// Example: Insert some initial data
	await db.collection('settings').insertOne({ key: 'appVersion', value: '1.0.0' });
	console.log('Inserted initial app version setting');

	return Promise.resolve();
};

exports.rollback = async function(params) {
	const { db, dropIndexIfExists } = params;

	// Example: Rollback by dropping the collection and index
	await dropIndexIfExists('users', 'email_1'); // 'email_1' is the default index name
	await db.collection('users').drop();
	console.log('Dropped users collection and index');

	await db.collection('settings').deleteOne({ key: 'appVersion' });
	console.log('Removed app version setting');

	return Promise.resolve();
};

view raw JSON →