1.0.3 • Published 7 years ago

mongoose-create-or-update v1.0.3

Weekly downloads
72
License
MIT
Repository
github
Last release
7 years ago

mongoose-create-or-update

A Promise-based Mongoose plugin for creating and updating documents in a single statement.

Build Status codecov NPM Version Greenkeeper badge Latest Documentation

Install

$ npm install mongoose mongoose-create-or-update --save

Usage

const mongoose = require('mongoose');

const dataSchema = new mongoose.Schema({
    'contents': String
});

dataSchema.plugin(require('mongoose-create-or-update'));

const dataModel = mongoose.model('data', dataSchema);
let dataId = null;

dataModel.createOrUpdate({
    '_id': dataId
}, {
    'contents': 'Lorem ipsum dolor sit amet'
}).then(data => {

    dataId = data._id;

    done();

}).catch(err => {

    console.log(err);

});

Documentation

View full documentation here.