You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creating a model before mongoose.connect produces a model where the model.init() returns a promise that is rejected.
The autoCreate and autoIndex are not buffered until the database is connected but instead determined at time of model creation and therefore the options on database have no effect. This problem was there already in mongoose 5.
In mongoose 6 it seems to default to autoCreate and attempt to create the collection without connection.
If the current behavior is a bug, please provide the steps to reproduce.
$ node bug.js
{ mongoose: '6.0.5', node: 'v14.17.6' }
MongooseError: Connection 0 was disconnected when calling `createCollection`
at NativeConnection.createCollection (/home/kohtala/js/node_modules/mongoose/lib/connection.js:563:31)
at /home/kohtala/js/node_modules/mongoose/lib/model.js:1354:13
at promiseOrCallback (/home/kohtala/js/node_modules/mongoose/lib/helpers/promiseOrCallback.js:10:12)
at Mongoose._promiseOrCallback (/home/kohtala/js/node_modules/mongoose/lib/index.js:1151:10)
at Function.createCollection (/home/kohtala/js/node_modules/mongoose/lib/model.js:1351:23)
at /home/kohtala/js/node_modules/mongoose/lib/model.js:1269:16
at /home/kohtala/js/node_modules/mongoose/lib/model.js:1273:5
at new Promise (<anonymous>)
at Function.init (/home/kohtala/js/node_modules/mongoose/lib/model.js:1272:16)
at Mongoose._model (/home/kohtala/js/node_modules/mongoose/lib/index.js:556:9)
What is the expected behavior?
Should buffer the init until there is a connection and keep the Promise unresolved until collection and indices are created, if allowed by the options given during connect.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js v14.17.6, mongoose 6.0.5, mongodb 4.1.1. Server would be 4.4.
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
Creating a model before
mongoose.connect
produces a model where themodel.init()
returns a promise that is rejected.The autoCreate and autoIndex are not buffered until the database is connected but instead determined at time of model creation and therefore the options on database have no effect. This problem was there already in mongoose 5.
In mongoose 6 it seems to default to autoCreate and attempt to create the collection without connection.
If the current behavior is a bug, please provide the steps to reproduce.
Produces output
What is the expected behavior?
Should buffer the
init
until there is a connection and keep the Promise unresolved until collection and indices are created, if allowed by the options given during connect.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js v14.17.6, mongoose 6.0.5, mongodb 4.1.1. Server would be 4.4.
The text was updated successfully, but these errors were encountered: