-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
No indexes created when connected to a replica set with readPreference specified #11976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This bug still happens if the |
@emrsin can you please clarify the issue you're seeing? |
@vkarpov15 if I set |
@emrsin that's expected behavior. MongoDB server doesn't allow any writes on secondaries, so trying to send a |
Is this still true? According to the MongoDB ticket NODE-2784, this error was a bug in MongoDB driver 3.6.0 which was fixed in 3.6.3. I see that mongoose is using MongoDB driver 5.7.0 nowadays. My read is that readPreference should not interfere with write operations like Indeed, as said above, |
@danopia that's fair, it looks like you can use |
Prerequisites
Mongoose version
6.2.4
Node.js version
14.16.0
MongoDB server version
5.0.9
Description
In mongoose 6.2.4, indexes defined on schema paths are not created automatically when readPreference is set on the ConnectOptions.
The problem was noticed during the upgrade from mongoose 5.10.19 to 6.2.4. New databases created after the upgrade have been missing indexes.
Potentially related to #11711 and #10631
Setting {autoIndex: true} as a schema option seems to be a workaround for now.
Steps to Reproduce
The snippet sets up two databases with the same schema. The schema defines two fields, one with a unique index.
When running with no args, the assert should fail, as only the _id index is created.
When running with '--no-read-pref' the indexes are created
Expected Behavior
The indexes should be created as the documentation states that autoIndex is true by default.
The text was updated successfully, but these errors were encountered: