Registry / database / mongo-to-postgres

mongo-to-postgres

JSON →
library0.0.6jsnpmunverified

Simple data migration tool to transfer collections from MongoDB to PostgreSQL tables using Mongoose and Knex. Current stable version is 0.0.6. Low release cadence (last update unknown). Key differentiators: handles field renaming, field redefinition, foreign keys, and many-to-many link tables in a single configuration object. Lightweight alternative to ETL tools for one-off migrations.

npm install mongo-to-postgres
INSTALL
IMPORT
SIG · MONGO-TO-POSTGRES
M
mongo-to-postgres
databasejavascriptv0.0.6
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 'mongo-to-postgres'
ESM default import only; no named exports.
migrate
const migrate = require('mongo-to-postgres').default
const migrate = require('mongo-to-postgres')
In CJS, require returns an object with a `default` property.
migrate
import migrate from 'mongo-to-postgres'
import { migrate } from 'mongo-to-postgres'
migrate is the default export, not a named export.

Shows full migration configuration with connections, field renames, redefines, foreign keys, and many-to-many link tables.

import migrate from 'mongo-to-postgres'; migrate({ connections: { mongo: process.env.MONGO_URL ?? 'mongodb://localhost/mydb', postgres: process.env.POSTGRES_URL ?? 'postgres://user:pass@localhost:5432/mydb' }, collections: [ { collectionName: 'users', tableName: 'users', fieldsRename: [['createdAt', 'created_at']], fieldsRedefine: [['status', 'active']] }, { collectionName: 'orders', tableName: 'orders', foreignKeys: { user_id: 'users' }, links: { items: ['orders__items', 'order_id', 'item_id'] } } ] });
Debug
Known issues
gotchaYou MUST respect the order of tables. Tables with foreign keys must be placed AFTER tables from which these keys originate.
fix
Order collections array by dependency: parent tables first, child tables later.
affects: >=0.0.0
gotchaThe package assumes destination PostgreSQL tables already exist in the correct schema. It does not create them.
fix
Create PostgreSQL tables and schema before running migration.
affects: >=0.0.0
gotchaThis package uses ES modules ('type': 'module'). Not compatible with CommonJS require without .default.
fix
Set type: module in package.json or use dynamic import().
affects: >=0.0.0
deprecatedPackage appears unmaintained; last version released over a year ago. No recent updates for new MongoDB or PostgreSQL versions.
fix
Consider alternative tools like pgloader or custom scripts.
affects: 0.0.6
Errors
Common errors & fixes
collectionName is required for each collection
Missing collectionName property in migration config
fix
Provide collectionName for every collection in the collections array.
Cannot find module 'mongo-to-postgres'
Package not installed or used in wrong module system
fix
Run npm install mongo-to-postgres and ensure type: module in package.json for ESM.
Table 'departments' does not exist
PostgreSQL table not created before migration
fix
Create all target tables in PostgreSQL before running the migration.
Upgrade
Version history
0.0.6latest on npm
Audit
Dependencies
mongooserequiredORM for MongoDB connection and data extraction
knexrequiredQuery builder for PostgreSQL connection and data insertion
Agent activity
7 hits · last 30 days
node
6
Resources
mongo-to-postgres — npm install mongo-to-postgres · libregistry