what's the delete used for? I didn't see such grammar before, can anybody help me? the code snippet is very easy and it is used the 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);
}
delete in JavaScript removes the property from the object.
var game = {
id: 1
}
console.log(game); // Object {id: 1}
delete game.id
console.log(game); // undefined
It is used to remove a property from an object. So in this instance it removes the _id property from updates