Express with socket.io emit - findOneAndUpdate -


quite new socket io express, using yo angular-express fullstack.

save , delete works fine, when come findoneandupdate doesn't seems work anymore. can help? there way can emit within controller?

/**  * broadcast updates client when model changes  */  'use strict';  var project = require('./project.model');  exports.register = function(socket) {   project.schema.post('save', function (doc) {     onsave(socket, doc);   });   project.schema.post('remove', function (doc) {     onremove(socket, doc);   }); }  function onsave(socket, doc, cb) {   socket.emit('project:save', doc); }  function onremove(socket, doc, cb) {   socket.emit('project:remove', doc); } 

according mongoose document pre , post middleware hooks init, validate, save, remove. if source code of findbyidandupdate function, find work in query, means pass pre , post's save middleware. (it has own query middleware)

however, can still make work rewrite findbyidandupdate function into

schema.findbyid(id, function(err, doc){    // update on doc.    doc.save(function(err){        // additional works.     }) }) 

the save function trigger save middleware , functions same findbyidandupdate.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -