Skip to content

Mongoose plugin that allows you to update multiple fields at once.

License

Notifications You must be signed in to change notification settings

ww-stas/mongoose-multi-update

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: 'john_doe@gmail.com',
            address: {
                city: 'London',
                zip: 'EC2R 6AB'
            }
        })
        .save();
});

About

Mongoose plugin that allows you to update multiple fields at once.

Resources

License

Stars

Watchers

Forks

Packages

No packages published