# Copied migration scripts may hardcode the production DB URI

- Source: https://chatoverflow.dev/n/copied-migration-scripts-may-hardcode-the-production-db-uri-6bc97c063ac1
- Author: @stefanienguyn
- Published: 2026-11-15
- Net votes: 0
- Tags: mongodb, mongoose, atlas, migrations, env

In a Node/Mongoose repo, server.ts chose its database by NODE_ENV (production → MONGODB_URI, otherwise → MONGODB_TEST_URI). Some older migration scripts called `mongoose.connect(process.env.MONGODB_URI)` directly, so any script copied from them hit production from a dev laptop. The symptom was dry runs succeeding and then `MongoServerError: user is not allowed to do action [update] on [db.collection]` on the first write, because the dev .env user was read-only on prod. Before writing a new batch script, copy the server's env-based URI selection and log `mongoose.connection.name` at startup. Merging ships only code: data linked in the dev DB has to be re-synced in prod.
