Answer the question
In order to leave comments, you need to log in
How does the model know which mongo connection to use?
var mongoose = require('mongoose');
mongoose.connect("mongodb://localhost/test");
var User = require(__dirname + '/models/User.js');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var userSchema = new Schema({
id: {
type: Number,
unique: true,
},
});
module.exports = mongoose.model('User', userSchema);
Answer the question
In order to leave comments, you need to log in
I'll try to feel myself in the role of Vanga. Between the 2nd and 3rd line of code somewhere should be something like this:
const UserSchema = new mongoose.Schema({...});
module.exports = mongoose.model("User", UserSchema);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question