Skip to content
A Promise-based Mongoose plugin for creating and updating documents in a single statement.
JavaScript Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.eslintrc
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
DOCUMENTATION.md
LICENSE
Makefile
README.md
index.js
package.json

README.md

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.

You can’t perform that action at this time.