Registry / database / postgres-to-mongo

postgres-to-mongo

JSON →
library2.1.0jsnpmunverified

A framework for converting PostgreSQL databases to MongoDB. Current version 2.1.0, with ongoing maintenance. It provides a schema-mapping approach to translate relational structures (tables, relationships, constraints) into MongoDB collections and documents. Key differentiators: supports complex type conversions, custom mapping rules, and preserves data integrity. Release cadence is irregular, with version 2.x having breaking changes from 1.x. Primarily used for one-time migrations or ETL pipelines.

npm install postgres-to-mongo
INSTALL
IMPORT
SIG · POSTGRES-TO-MONGO
P
postgres-to-mongo
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.

convert
import { convert } from 'postgres-to-mongo'
const convert = require('postgres-to-mongo')
ESM-only since v2.0.
MappingConfig
import type { MappingConfig } from 'postgres-to-mongo'
const { MappingConfig } = require('postgres-to-mongo')
Only available as a type; cannot be imported as a value.

Connects to PostgreSQL and MongoDB, converts specified tables to collections using mapping configuration.

import pg from 'pg'; import { MongoClient } from 'mongodb'; import { convert } from 'postgres-to-mongo'; const pgClient = new pg.Client({ connectionString: process.env.PG_URL ?? '' }); const mongoClient = new MongoClient(process.env.MONGO_URL ?? ''); async function main() { await pgClient.connect(); await mongoClient.connect(); const config = { tableMapping: { 'users': { collection: 'users', primaryKey: 'id' }, 'orders': { collection: 'orders', primaryKey: 'id' } } }; const result = await convert(pgClient, mongoClient, config); console.log(`Converted ${result.totalDocuments} documents`); await pgClient.end(); await mongoClient.close(); } main().catch(console.error);
Debug
Known issues
breakingv2.0.0: Switched from CommonJS to ESM; synchronous API replaced with async/await.
fix
Update imports to use ESM syntax and wrap calls in async functions.
affects: >=2.0.0
deprecatedv2.0.0: The old pg-promise integration is deprecated; use 'pg' package with config objects.
fix
Replace pg-promise usage with 'pg' Client and pass config as second argument.
affects: >=2.0.0
gotchaPostgreSQL arrays are converted to MongoDB arrays, but nested arrays may not be flattened correctly.
fix
Manually handle nested arrays by providing a custom type transformer in the mapping config.
affects: <=2.1.0
Errors
Common errors & fixes
TypeError: convert is not a function
Using CommonJS require() for an ESM-only package.
fix
Use 'import { convert } from "postgres-to-mongo";' and ensure project is configured for ESM.
Error: Mapping config is required
Calling convert() without a mapping configuration object.
fix
Provide a config object with at least 'tableMapping' property.
Error: Relation not found
Referencing a table name that does not exist in the source PostgreSQL database.
fix
Check the table name in the config matches actual table names in PostgreSQL.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
postgres-to-mongo — npm install postgres-to-mongo · libregistry