猫鼬,保存查找结果似乎无济于事

stack_pooper

我有两个架构,FinishedGamePlayingGame两种模式都是相同的。当我关闭游戏时,想要将其复制PlayingGameFinishedGame集合中,然后将其删除PlayingGame现在的代码似乎没有引发错误,但也没有添加任何内容FinishedGame当我打开shell运行时,show collections我只会看到playinggamessystem.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');
            });
        });
    }

});
香港强尼

你需要调用toObject()game它传递给之前FinishedGame的构造,因为它是期待一个简单的JS对象,而不是猫鼬文档实例。

因此,将该行更改为:

var finishedGame = new FinishedGame(game.toObject());

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章