node.js“删除”的奇怪语法

时间:2013-02-13 11:20:06

标签: node.js mongodb mongoose

删除用于什么?我之前没有看过这样的语法,有人可以帮帮我吗? 代码片段非常简单,它用于node.js,mongoose,mongodb

function _update(game, callback) {
    if (!game) {
        callback(new Error("Game must be provided."));
        return;
    }
    if (!game.gameId) {
        callback(new Error("Game id should be provided"));
        return;
    }

    var updates = (game instanceof Game) ? game.toObject() : game;
    delete updates._id;
    updates.modifiedDate = new Date();

    Game.findOneAndUpdate({"_id": game.id, "deleted" : {"$ne": true}}, updates, callback);
}

2 个答案:

答案 0 :(得分:2)

JavaScript removes the property from the object中的

delete

var game = {
    id: 1
}

console.log(game);  // Object {id: 1}

delete game.id

console.log(game);  // undefined

答案 1 :(得分:1)

用于从对象中删除属性。所以在这个例子中,它从更新中删除了_id属性