Prerequisites
Issue
In connection in the section of exporting models with createConnection there is a fast.js and slow.js example. Why is the other slower? Should we always use the faster way? Should we separate models in different files for the same connection? This is not explained.
Here is the possible wrong part:
It says to export the connection
const conn = mongoose.createConnection(process.env.MONGODB_URI);
conn.model('User', require('../schemas/user'));
module.exports = conn;
But this gives a "Not a function" error when trying to use it in another file.
However I got it to work by exporting the model with
const conn = mongoose.createConnection(process.env.MONGODB_URI);
const User = conn.model('User', require('../schemas/user'));
module.exports = User;
Is this the right way to do it?
I am using Mongoose 8.1.3, Node 18.12.1, MongoDB 6.0.3
Prerequisites
Issue
In connection in the section of exporting models with createConnection there is a fast.js and slow.js example. Why is the other slower? Should we always use the faster way? Should we separate models in different files for the same connection? This is not explained.
Here is the possible wrong part:
It says to export the connection
But this gives a "Not a function" error when trying to use it in another file.
However I got it to work by exporting the model with
Is this the right way to do it?
I am using Mongoose 8.1.3, Node 18.12.1, MongoDB 6.0.3