Created
November 3, 2012 18:50
-
-
Save hurrymaplelad/4008255 to your computer and use it in GitHub Desktop.
Attempts to remove an attribute from mongo docs that isnt defined in the mongoose schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var broccoli = new Food({ | |
name: 'frozen broccoli', | |
organic: true | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Food.collection.update({}, | |
{$unset: {organic: true}}, | |
{multi: true, safe: true}, | |
function(err) { | |
Food.findById(broccoli, function(err, brocolli) { | |
console.log(broccoli.get('organic')); | |
} | |
); | |
> undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Food.update({}, | |
{$unset: {organic: true}}, | |
{multi: true, safe: true}, | |
function(err) { | |
Food.findById(broccoli, function(err, broccoli) { | |
console.log(broccoli.get('organic')); | |
}); | |
} | |
); | |
> true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Food.findById(broccoli, function(err, broccoli) { | |
console.log(broccoli.get('organic')); | |
}); | |
> true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Food = db.model('Food', new mongoose.Schema({ | |
name: {type: String, required: true}, | |
- organic: Boolean | |
}, { | |
strict: true | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
broccoli.save(function() { | |
Food.findById(broccoli, function(err, broccoli) { | |
console.log(broccoli.get('organic')) | |
}) | |
}); | |
> true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Food = db.model('Food', new mongoose.Schema({ | |
name: {type: String, required: true}, | |
organic: Boolean | |
}, { | |
strict: true | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Food.collection.update({}, | |
{$unset: {organic: true}}, | |
{multi: true, safe: true} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
broccoli.set('organic', undefined); | |
broccoli.save(function() { | |
Food.findById(broccoli, function(err, broccoli) { | |
console.log(broccoli.get('organic')); | |
}); | |
}); | |
> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment