Tell us what’s happening:
Save does not appear to work because the res.json
is not returned. How can this be solved?
// define the database
var userSchema = new mongoose.Schema({
username: String,
_id: String,
});
// create the Model
var User = mongoose.model('User', userSchema);
app.post("/api/exercise/new-user", (req, res) => {
var _id = shortid.generate();
var username = req.body.username
var user = new User({ username: username, _id: _id});
user.save({ username: username }, (error, data) => {
if (err) return console.error(err);
if (data) {
res.json({
username: username,
_id: _id
});
}
});
});
Your code so far
https://repl.it/@controlunit/boilerplate-project-exercisetracker#server.js
Your browser information:
Chromium
Challenge: Exercise Tracker
Link to the challenge: