Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRyan Morales
Full Stack JavaScript Techdegree Graduate 33,933 PointsHow do I add data to existing user in mongoose schema from a running express app - Dave Macfarland authentication course
I completed Dave's authentication with express and mongo course and I wanted to continue with the project by adding info to an existing user but I'm stuck. After registering a user, I want the logged in user to be able to answer questions and those answers be added to their schema, then displayed on their profile page. I cannot figure it out. Here is some of the code
//models/user.js
var UserSchema = new mongoose.Schema({
email: {
type: String,
unique: true,
required: true,
trim: true
},
userName: {
type: String,
required: true,
trim: true
},
name: {
type: String,
required: true,
trim: true
},
favoriteBook: {
type: String,
required: true,
trim: true
},
password: {
type: String,
required: true
}
});
var User = mongoose.model('User', UserSchema);
module.exports = User;
// index.js
// GET /user-survey
router.get('/user-survey', function(req, res, next) {
return res.render('user-survey', { title: 'User Survey' });
});
// POST /user-survey
router.post('/user-survey', function(req, res, next) {
/*
User.update(query, { surveyanswer1: 'Some personal information' };
*/
Thanks!
Ashish Mehra
588 PointsAshish Mehra
588 PointsHey Ryan Morales, I got your question and if you want to implement a functionality to make logged in users able to answer the questions available in the page and then display all the question with answer in a user profile.
So here are the steps for this :