sql >> Base de Datos >  >> NoSQL >> MongoDB

Mongodb no se actualiza cuando lo uso así

{_where : what } trata _where como una String literal, que es equivalente a:{"_where":what} . Por lo tanto, no obtiene ningún resultado actualizado ya que no hay un campo como _where . Debe asignarlo de la siguiente manera para que funcione.

exports.updateUsers = function ( user_id, where, what, pass )  {
    var _where = 'settings.'+where; //when I use it doesn't update
    var update = {};
    update[_where] = what;
    user.findOneAndUpdate(
          {'user_id' : user_id}, 
          update).exec(function(e,d){
            pass("ok")
          })
};

update[_where] = what; resuelve el valor en _where variables.