Would you like to contribute to the Titanium docs? To get started, sign up for an account on the Appcelerator Wiki and sign our CLA.

Skip to end of metadata
Go to start of metadata

Mobile Backend Services supports the Mongo $inc atomic increment operator.

$inc

You can use $inc to increment (or decrement) a custom field by a specified value in a single update operation.

  • The operator accepts positive and negative increment amounts
  • It can only be applied to a single field per method call.

$inc is specified with the following form, where fieldName is the name of the field to update and value is a positive (or negative) number to increment (or decrement) fieldName by:

The operator must be enclosed quotes, as shown above. The following methods support the $inc operator:

Examples

The following example increments the score custom field by 10 in a CustomObjects update to a custom object called family:

 Expand source

The following example decrements the score custom field by 20 in a Checkins update:

 Expand source

If you apply $inc to multiple fields in one Update call, you will get an error: