0
查詢模型後,我無法調用每個模型的方法。節點在查詢模型上的Mongoose調用方法
var mongoose = require('mongoose'),
Player = mongoose.model('Player');
Player.find({ controller : 'user' , 'timestamps.ai_last_spawned_at': { $lt: (Date.now() - settings.ai_spawn_interval) } }, function(err, players){
if(err) throw err;
console.info('Spawning AI for', players.length , 'players');
_.each(players, function(player){
player.spawnAi();
});
});
,並在架構,我有:
playerSchema.methods.spawnAi = function(options, cb){ }
錯誤我得到的是使用苦厄它只存儲對象的數據
TypeError: Object #<Object> has no method 'spawnA'