MongooseJS保存将不会调用callback

我正在使用MongooseJS连接到MongoDB

我正在创build一个新的团队。 一旦我保存了团队,我想为我的用户添加一个对团队的引用。 但不幸的是,每当我去添加团队到我的用户和保存用户我的callback不被调用。 任何想法为什么?

TeamRepository.prototype.createForUser = function(user, data, callback) { var team, _this = this; if (user == null) { user = null; } if (data == null) { data = {}; } if (callback == null) { callback = (function() {}); } team = new Team({ name: data.name, description: data.description, state: data.state }); return this.save(team, function(err) { if (err) { return callback(err, team); } else { user.teams.push({ team: team._id }); return _this.save(user, function(err) { return callback(err, team); }); } }); }; 

具体这一行。 注意我有两个嵌套的保存。

 return _this.save(user, function(err) { return callback(err, team); }); 

任何帮助将是伟大的。

我已经解决了这个问题。 在我的用户模型中,我挂钩了保存事件,并没有调用next()来移动保存。

 schema.pre('save', function(next) { var _this = this; if (this.isNew || this.isModified('password')) { return hashPassword(this.password, function(err, hash) { if (err) { return next(err); } _this.password = hash; return next(); }); } else { return next(); // missing this } }); 

自从你问起这里是我的TeamRepository.save()的样子。

 TeamRepository.prototype.save = function(model, callback) { if (model == null) { model = null; } if (callback == null) { callback = (function() {}); } if (model) { model.increment(); return model.save(callback); } else { if (callback) { return callback(null); } } };