J
J
JIakki2015-08-31 11:25:23
MongoDB
JIakki, 2015-08-31 11:25:23

Why isn't data being updated in MongoDB?

var User = require('../../models/user')
var mongoose = require('mongoose')

module.exports = function (req, res) {
  var post = req.body // post.name === new value
  
  User.findById(req.user._id, function (err, user) {
    if(err) return console.log(err);

    user.data.moneySource[post.index].name = post.name;

    user.save(function (err) {
      if(err) return console.log(err)
      console.log(user.data.moneySource[post.index].name) // it returns NEW value
    })
  })

But the changes are not made to the database
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill, 2015-08-31
@kirill89

Please show the model code. If the data field or data.moneySource is of type Schema.Types.Mixed you must use the markModified method on the document to notify mongoose of the change. You can read more here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question