mongoose-multi-update
v0.1.1
Published
Mongoose plugin that allows you to update multiple fields at once.
Downloads
3
Readme
Mongoose Multi Update Plugin
Mongoose plugin that allows you to update multiple fields at once.
Installation
npm install mongoose-multi-update --save
Usage
Require plugin in your schema
// UserSchema.js
var multiUpdate = require('mongoose-multi-update');
var UserSchema = new Schema({
username: String,
email: String,
address: new Schema({
city: String,
zip: Number,
street: String,
phone: String
})
});
//require plugin
UserSchema.plugin(multiUpdate);
You may update one nested field:
User.findById('someID', function(err, user) {
user
.multiUpdate({
address: {
city: 'London'
}
})
.save();
});
You may update all fields at once:
User.findById('someID', function(err, user) {
user
.multiUpdate({
username: 'John Doe',
email: '[email protected]',
address: {
city: 'London',
zip: 'EC2R 6AB'
}
})
.save();
});