Hi! So I’m working on the exercise tracker project and I get an error when starting the server. I tried to find the cause of the error in google but couldn’t find something helpful.The error occurs on the provided part of server.js file and precisely in then()
after the console.log("connected");
Error message:
Something went wrong ObjectParameterError: Parameter "obj" to Document() must be an object, got function(req, res, next) {
app.handle(req, res, next);
}
at...
.
.
.
at path/to/server.js/server.js
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Here are 2 pieces of code (User model and the part of server.js where getting the error)
user.js:
var mongoose = require('mongoose');
const { Schema } = mongoose;
// Define user schema
const userSchema = new Schema({
username: {type: String, required: true},
exercises: [Object]
});
module.exports = mongoose.model('User', userSchema);
server.js:
mongoose.connect(process.env.MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true}).then(() => {
console.log('connected');
user(app)
exercise(app)
routes(app)
})
.catch((e) => {
console.log("Something went wrong", e);
});