Automattic/mongoose · error · MongooseError
MongoDB prohibits index creation on connections that read fr
Error message
MongoDB prohibits index creation on connections that read from non-primary replicas. Connections that set "readPreference" to "secondary" or "secondaryPreferred" may not opt-in to the following connection options: autoCreate, autoIndex
What it means
Error "MongoDB prohibits index creation on connections that read from non-primary replicas. Connections that set "readPreference" to "secondary" or "secondaryPreferred" may not opt-in to the following connection options: autoCreate, autoIndex" thrown in Automattic/mongoose.
Source
Thrown at lib/helpers/processConnectionOptions.js:57
function setsSecondaryRead(prefString) {
return !!(prefString === 'secondary' || prefString === 'secondaryPreferred');
}
function getUriReadPreference(connectionString) {
const exp = /(?:&|\?)readPreference=(\w+)(?:&|$)/;
const match = exp.exec(connectionString);
return match ? match[1] : null;
}
function defaultIndexOptsToFalse(opts) {
opts.config = { autoIndex: false };
opts.autoCreate = false;
opts.autoIndex = false;
return opts;
}
function throwReadPreferenceError() {
throw new MongooseError(
'MongoDB prohibits index creation on connections that read from ' +
'non-primary replicas. Connections that set "readPreference" to "secondary" or ' +
'"secondaryPreferred" may not opt-in to the following connection options: ' +
'autoCreate, autoIndex'
);
}
module.exports = processConnectionOptions;
View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/helpers/processConnectionOptions.js:57 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/f1200c31db9791e3.
Report an issue: GitHub.