{"id":25413694,"url":"https://github.com/alxnkt/mongo-to-postgres","last_synced_at":"2025-10-31T07:31:22.013Z","repository":{"id":41558299,"uuid":"257058897","full_name":"alxnkt/mongo-to-postgres","owner":"alxnkt","description":"Simple data migration from MongoDb to PostgreSQL","archived":false,"fork":false,"pushed_at":"2024-03-23T12:52:21.000Z","size":520,"stargazers_count":11,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-23T14:43:28.980Z","etag":null,"topics":["database","migration","mongo","postgres"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/mongo-to-postgres","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alxnkt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-19T17:19:12.000Z","updated_at":"2024-04-19T19:04:22.000Z","dependencies_parsed_at":"2024-03-23T14:00:50.216Z","dependency_job_id":null,"html_url":"https://github.com/alxnkt/mongo-to-postgres","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxnkt%2Fmongo-to-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxnkt%2Fmongo-to-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxnkt%2Fmongo-to-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alxnkt%2Fmongo-to-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alxnkt","download_url":"https://codeload.github.com/alxnkt/mongo-to-postgres/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239126477,"owners_count":19586099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","migration","mongo","postgres"],"created_at":"2025-02-16T14:21:38.219Z","updated_at":"2025-10-31T07:31:21.660Z","avatar_url":"https://github.com/alxnkt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple data migration from MongoDb to PostgreSQL\n\nThis tiny tool is used for easy data migration from MongoDb database\nto PostgreSQL database. It uses appropriate ORMs: `mongoose` and \n`knex` respectively to transfer data.\n\n## Requirements\n* Node.js 13+\n* MongoDb 4+\n* PostgreSQL 12+\n\n## Usage\n\n### 1. Install package\n\n`$ yarn add mongo-to-postgres`\n\nOR\n\n`$ npm i mongo-to-postgres`\n\n### 2. Create file `migrate.js`, set migration settings in it\n\n**IMPORTANT NOTES**\n\n**1. You MUST respect the order of the tables. Tables with foreign keys MUST BE placed AFTER tables, from which these keys are.**\n\n**2. This sample assumes that you have postgres database with schema, containing empty tables.**\n\n```javascript\nimport migrate from 'mongo-to-postgres';\n\nmigrate({\n  // Define connection strings\n  connections: {\n    mongo: 'mongodb://localhost/dbname',\n    postgres: 'postgres://postgres:secret@localhost:5432/dbname'\n  },\n  // Define your database migration settings\n  collections: [\n    {\n    collectionName: 'department',  // collection name in Mongo\n    tableName: 'departments',      // table name in Postgres\n    fieldsRename: [\n      ['createdAt', 'created_at'], // set new name for field (optional)\n      ['updatedAt', 'updated_at']  // set new name for other field (optional)\n    ],\n    fieldsRedefine: [\n      ['dep_type', 1]              // force to set value for all records (optional)\n    ]\n  },\n  {\n    collectionName: 'award',       // collection name in Mongo\n    tableName: 'awards',           // table name in Postgres\n  },\n  {\n    collectionName: 'employee',    // collection name in Mongo\n    tableName: 'employees',        // table name in Postgres\n    foreignKeys: {\n      department: 'department',    // foreign keys (field: collection) (optional)\n    },\n    links: {                       // \"many-to-many\" links\n      awards: ['emplyees__awards', 'employee_id', 'award_id']\n    }\n  }\n  ]\n});\n```\n\n### 3. Set `package.json` `\"type\"` field\n\n```json\n{\n  \"type\": \"module\",\n  \"dependencies\": {\n    \"mongo-to-postgres\": \"^0.0.5\"\n  }\n}\n```\n\n### 4. Run migration\n\n`$ node migrate.js`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxnkt%2Fmongo-to-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falxnkt%2Fmongo-to-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falxnkt%2Fmongo-to-postgres/lists"}