npm.io
1.0.1 • Published 9 years ago

mongoose-upsert

Licence
MIT
Version
1.0.1
Deps
0
Vulns
0
Weekly
0
Stars
1

#Mongoose upsert

A Schema plugin that adds an upsert method to a model generated from that schema. It is simply a shortcut to

Model.update( { query }, { doc }, { upsert : true } )

Installation

npm install mongoose-upsert

Usage

var upsert = require('mongoose-upsert');
var MySchema = new Schema({ ... });
MySchema.plugin(upsert);
My = mongoose.model('My', MySchema);

...

My.upsert({ _id : 123 }, { somevalue : "New or initial value" });