Add and Manage Data
Increment Numeric Data
Learn how to increment numeric data in your WorqDB Document
You can increment or decrement a numeric field value as shown in the following example. An increment operation increases or decreases the current value of a field by the given amount.
To increment a numeric field value, use a POSITIVE
number. To decrement a numeric field value, use a NEGATIVE
number.
The Increment operation is only available for numeric fields and will only work if the Field has either been declared during a
Add
operation or has been updated with a Update
operation. If the Field doesn’t exist, the Increment operation will fail.Initialize Database Modules
const worqhat = require('worqhat');
var config = new worqhat.Configuration({
apiKey: "your-api-key",
debug: true,
max_retries: 3,
});
worqhat.initializeApp(config);
let db = worqhat.database();
Increment Numeric Data
db.collection('NodeJSDb1').doc('de79272c-2ed3-46d9-ae93-ff195364466e').update({
age: db.increment(10)
}).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
});
Decrement Numeric Data
db.collection('NodeJSDb1').doc('de79272c-2ed3-46d9-ae93-ff195364466e').update({
age: db.increment(-10)
}).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
});
Was this page helpful?