-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
docsThis issue is due to a mistake or omission in the mongoosejs.com documentationThis issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
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
Metadata
Metadata
Assignees
Labels
docsThis issue is due to a mistake or omission in the mongoosejs.com documentationThis issue is due to a mistake or omission in the mongoosejs.com documentation