{"id":19301927,"url":"https://github.com/payloadcms/migrate-mongo-example","last_synced_at":"2025-10-06T14:10:51.231Z","repository":{"id":103210918,"uuid":"581196845","full_name":"payloadcms/migrate-mongo-example","owner":"payloadcms","description":"Payload project using migrate-mongo to demonstrate migrations","archived":false,"fork":false,"pushed_at":"2022-12-22T14:40:43.000Z","size":195,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-22T10:33:24.655Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/payloadcms.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":"2022-12-22T14:28:19.000Z","updated_at":"2025-03-26T07:56:49.000Z","dependencies_parsed_at":"2023-06-28T23:46:02.120Z","dependency_job_id":null,"html_url":"https://github.com/payloadcms/migrate-mongo-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/payloadcms/migrate-mongo-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/payloadcms%2Fmigrate-mongo-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/payloadcms%2Fmigrate-mongo-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/payloadcms%2Fmigrate-mongo-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/payloadcms%2Fmigrate-mongo-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/payloadcms","download_url":"https://codeload.github.com/payloadcms/migrate-mongo-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/payloadcms%2Fmigrate-mongo-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278621853,"owners_count":26017255,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-09T23:19:20.951Z","updated_at":"2025-10-06T14:10:51.224Z","avatar_url":"https://github.com/payloadcms.png","language":"JavaScript","readme":"# Migrate Mongo Payload Example\n\nThis repo is a working demonstration of using `mongo-migrate` in a Payload CMS project\n\n## In a real world scenario\n\n1. App is developed\n2. Tested\n3. Goes to production\n4. Actual data is created over time\n5. App needs to have data changed on fields and collections with existing data\n\nThis is a demonstration of what to do at this step.\n\n## Recreating this setup\n1. `npx create-payload-app`\n2. `cd` to newly created project\n3. `yarn add migrate-mongo`\n4. `yarn migrate-mongo init`\n5. Customize your migrate-mongo-config.js to have the connection string of your mongo database\n6. Add script to package.json to make using migrations easier `\"migrate\": \"migrate-mongo\"`\n\nSee example changes in [Users.ts](src%2Fcollections%2FUsers.ts), changes to name fields left in comments.\nSee migration [20221221120758-update-users-change-name.js](migrations%2F20221221120758-update-users-change-name.js)\n\n## Workflow for development\n1. Make changes to existing Payload collections\n2. If a migration to change existing data is necessary:\n3. `yarn migrate create update_collection-name_rename_field`, come up with a consistent format \u0026 naming convention for migration files\n4. Write the `up` and `down` functions to perform the changes needed, test using local data with simulated production data\n5. Commit both the migrations and code changes together in a branch and merge it\n6. When pulling changes to a new environment (dev, staging, prod) with data, run `yarn migrate up` and `yarn migrate status` to verify\n\nMigrations are only needed when existing data has changed, they are not needed for simply adding a new field or index. Another use-case for migrations is to insert necessary data for applications to function. Suppose you are adding `roles` as a relationship to be defined on User collections which you want stored in the database and consistent across environments, this is one example and there are many more.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpayloadcms%2Fmigrate-mongo-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpayloadcms%2Fmigrate-mongo-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpayloadcms%2Fmigrate-mongo-example/lists"}