私はFinishedGame
とPlayingGame
という2つのスキーマを持っています。どちらのスキーマも同じです。ゲームを終了するときに、PlayingGame
をFinishedGame
コレクションにコピーしてから、PlayingGame
を削除します。今のコードではエラーが発生しないようですが、FinishedGame
には何も追加されません。シェルを実行すると、実行show collections
私はplayinggames
とを参照してください。 何か助けていただければ幸いです。マングース、検索結果を保存しても何もしないようです。
相続人は、私はゲームを閉じたいときに実行されるコード:
あなたはそれが、マングースプレーンJSオブジェクトをない期待だとしてFinishedGame
コンストラクタに渡す前
game
に
toObject()
を呼び出す必要が
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');
});
});
}
});
おそらく、 'game'はidによって見つからないでしょうか?コンソールで 'ゲームを完成したゲームに保存する'メッセージが表示されますか? – alexmac
これは@JohnnyHKに投稿しました。回答を投稿すると選択できます –