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
Connection autoCreate option behaves differently migrating 5 to 6 #12940
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
IslandRhythms
added
the
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
label
Jan 25, 2023
Just to double check, is your assertion suppose to pass or fail? const mongoose = require('mongoose');
const testSchema = new mongoose.Schema({
name: String
}, { collation: { locale: 'en_US', strength: 1 }, collection: 'gh8814_Conn' });
const Test = mongoose.model('gh8814_Conn', testSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017', { autoCreate: false });
await Test.init();
const res = await mongoose.connection.db.listCollections().toArray();
console.log(res);
await mongoose.connection.dropDatabase();
};
run(); |
The assertion fails, and I think the code should be changed to make the test pass. The gh8814_Conn collection shouldn't be created (following the |
lpizzinidev
added a commit
to lpizzinidev/mongoose
that referenced
this issue
Feb 8, 2023
lpizzinidev
added a commit
to lpizzinidev/mongoose
that referenced
this issue
Feb 20, 2023
lpizzinidev
added a commit
to lpizzinidev/mongoose
that referenced
this issue
Feb 20, 2023
lpizzinidev
added a commit
to lpizzinidev/mongoose
that referenced
this issue
Feb 21, 2023
vkarpov15
added a commit
that referenced
this issue
Feb 21, 2023
fix(connection): disable createConnection buffering if autoCreate option is changed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
6.8.4
Node.js version
18.13.0
MongoDB server version
4.12.1 (driver)
Typescript version (if applicable)
No response
Description
When upgrading from Mongoose 5.13.15 to 6.8.4, we switched to explicitly setting the
autoCreate
option tofalse
on the connection. We previously never set the autoCreate option on our Schema objects, so they should default to null (which means use the connection's autoCreate option). Our Schemas instantiate before the connection is created.We found that in Mongoose 6, the autoCreate commands buffered prior to the connection being created were executed, issuing createCollection commands to the database. This didn't happen previously in Mongoose 5.
Workaround was to explicitly set autoCreate to false on the Schema objects.
Steps to Reproduce
Added to
test/connection.test.js
Expected Behavior
Schema with
autoCreate: null
option set follows the connection'sautoCreate
option, even if schema is initialized first and the createCollection command is buffered.The text was updated successfully, but these errors were encountered: