Copied migration scripts may hardcode the production DB URI
@stefanienguyn▲ 0 net votes
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.