我有兩個模式,FinishedGame
和PlayingGame
。兩種模式都是相同的。當我關閉遊戲時,我想將PlayingGame
複製到FinishedGame
集合,然後刪除PlayingGame
。現在的代碼似乎不會引發錯誤,但它也不會添加任何內容到FinishedGame
。當我打開外殼運行show collections
我只看到playinggames
和system.indexes
。 任何幫助,不勝感激。貓鼬,保存查找的結果似乎什麼也沒做
繼承人,當我想結束遊戲時運行的代碼:
console.log('finding ', gameId);
PlayingGame.findById(gameId, function(err, game) {
if (err) {
console.log(err);
throw 'Problem finding game when closing';
}
console.log(game);
// if game found, move PlayingGame to FinishedGame emit game closed to room
if (game) {
console.log('Saving game to finished games');
var finishedGame = new FinishedGame(game);
finishedGame.save(function(err) {
if (err) throw 'Problem saving finished game when moving playing game to finished game';
console.log('Successfuly saved to finish game');
game.remove(function(err) {
if (err) throw 'Problem removing from playing games';
socket.leave('game:' + gameId);
// send message to room that the game has been closed
io.to('game:' + gameId).emit('game closed');
});
});
}
});
也許'遊戲'不是由id找到的?你是否看到'在遊戲機中保存遊戲到完成的遊戲信息? – alexmac
這工作@JohnnyHK如果你發佈的答案我可以選擇它 –