Saturday 15 February 2014

javascript - User save not saving with no errors -



javascript - User save not saving with no errors -

i have next code updating todos:

router.post('/edit/todo', function(req, res) { var post = req.body, newtitle = post.title, newdetails = post.details.replace(/\n/g, '<br>'), // _id = post._id; index = post.index; console.log('req.user.todos[index] = ' + json.stringify(req.user.todos[index])); // old details req.user.todos[index].title = newtitle; req.user.todos[index].details = newdetails; req.user.save(function(err) { if (err) homecoming console.log(err); else { console.log('req.user.todos[index] = ' + json.stringify(req.user.todos[index])); // new details res.redirect('/'); } }); }); router.get('/', function(req, res) { var todos = req.user.todos; // old details }

here user schema:

var userschema = new mongoose.schema({ name: { type: string, required: true }, email: { type: string, unique: true, required: true }, password: { type: string, required: true }, // keeps tasks homework , projects // each todo made of title, , details todos: [], // keeps test // each test made of subject , date // each date made of month , day tests: [], // keeps schedule // used tomorrow tile schedule: { }, // links school related sites // each link made of name , href links: [] });

this weird because in saving stage goes through no errors, , shows new details, seems doesn't save user. also, have same thing creating todos (just push instead of putting values) , works perfectly.

because don't define todo array contains in schema, need tell mongoose when you've modified info within elements calling markmodified:

req.user.todos[index].title = newtitle; req.user.todos[index].details = newdetails; req.user.markmodified('todos');

javascript node.js mongodb mongoose passport.js

No comments:

Post a Comment