A no-dependency module that adds an upsert
function to the nodejs-cloudant module.
npm install cloudant-upsert
The following adds the upsert
function to a cloudant
instance
var Cloudant = require('@cloudant/cloudant');
var cloudant = Cloudant('<YOUR_CLOUDANT_URI>');
require('cloudant-upsert')(cloudant);
In the example below prevdoc
contains null
or the previous doc
cloudant.db.use('mydb').upsert('carmine', prevdoc => ({
"text": "Woop Woop! We're using promises",
}))
.then(r => console.log('result', r))
.catch(e => console.log('error', e.message));
In the example below prevdoc
contains null
or the previous doc
cloudant.db.use('mydb').upsert('carmine', prevdoc => ({
"text": "Woop! Woop! We're using callbacks"
}), (err, data) => {
if (err) console.log('error', err.reason)
else console.log('data', data)
})
param | description |
---|---|
id |
The document id to upsert |
function(prevdoc): doc |
A function that provides the previous document (or null when inserting a new doc) as input. You must return the document to upsert. |
param | description |
---|---|
id |
The document id to upsert |
function(prevdoc): doc |
A function that provides the previous document (or null when inserting a new doc) and returns a new document to upsert |
function(err, res): void |
A Node.js error first callback |