Back to Top

mongoose-create-or-update master

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

scheme.statics.createOrUpdate(query[, update, options])

Creates or updates an existing document in a Mongoose model.

Parameters

Name Type Description
query Object

Query object.

update Object

Updated object. See http://mongoosejs.com/docs/api.html#model_Model.update for more information.

Optional
options Object

Options object. See http://mongoosejs.com/docs/api.html#model_Model.update for more information.

Optional

Examples

dataModel.createOrUpdate({'_id': 'xxxx'}, {'updatedAt': Date.now()}).then(function (data) { console.log(data); });

Returns

Object

Promise