Document start
var mongoose = require( 'libs/mongoose' ), Schema = mongoose.Schema, async = require( 'async' ), AuthError = require( 'libs/errors' ).AuthError, Task = require( 'models/task').Task, authCheck = require( 'libs/auth' ), crypto = require( 'crypto' ), UserSchema = new Schema ({ /* ..... */ }); The following code just freezes
UserSchema.statics.addTasks = function ( task, callback ) { var User = this; async.waterfall([ function ( callback ) { User.findById( task.userId, callback ); }, function ( user, callback ) { user.update( { $push: { tasks: task._id } }, callback ); } ], callback ); }; Changed the standard callback to your own, throws an error
UserSchema.statics.addTasks = function ( task, callback ) { var User = this; async.waterfall([ function ( callback ) { User.findById( task.userId, callback ); }, function ( user, callback ) { user.update( { $push: { tasks: task._id } }, function ( err, user ) { console.log( arguments ); // { '0': null, '1': { ok: 1, nModified: 1, n: 1 } } return callback( err, user ); // TypeError: callFn.apply is not a function } ); } ], callback ); }; I also call the User.addTask method in the async chain,
attempt to replace this method with one function
User.findOneAndUpdate(/*...*/) hangs on the callback, and in the case of replacing the standard with its function, it throws
callback is not a function