javascript - Node/Express not saving updated company information to DB -


i'm new node/express, , trying implement block updates company's information. have number of console.log statements tracking variables throughout block, , seems working fine until last saving line. doing wrong?

// edit company metric information   editmetrics: function(link, form, cb) {     companies.findone({ permalink: link }, function (err, company) {       if (err)  return done(err);        // iterate through form fields       for(var field in form) {         console.log(field);  // looks great          if(typeof(company.operational[field]) !== 'undefined') {           company.operational[field].unshift({             timestamp: new date(),             value: form[field]           });         }          if(typeof(company.user_metrics[field]) !== 'undefined') {           company.user_metrics[field].unshift({             timestamp: new date(),             value: form[field]           });         }          if(typeof(company.economics[field]) !== 'undefined') {           company.economics[field].unshift({             timestamp: new date(),             value: form[field]           });          }             }        console.log(company); // looks great        // save & redirect updated profile       company.save(cb());  // reason isn't saving     });   }, 

callback:

companymodel.editmetrics(link, req.body, cb = function(error, result) {      res.redirect('/portfolio/' + link);    }); 

the problem last line:

company.save(cb());

should be:

company.save(cb);

basically executing callback , passing result save function, when need passing function pointer save function.

also make sure callback signature matches node convention of function(error, result) result value expecting.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -