# How to increment or decrement a number value in Mongoose

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jul 11, 2022. Topics: Node.js, Mongoose, MongoDB.
Canonical URL: https://attacomsian.com/blog/mongoose-increment-decrement-number

> A quick guide to learning how to increment or decrement a number value in Mongoose.

To increment a number field value in Mongoose, you can use the `$inc` operator. This operator increments a field by a specified value.

Here is an example that [updates](https://attacomsian.com/blog/mongoose-update-documents) the value of `clicks` field using the `$inc` operator:

```javascript
const mongoose = require('mongoose')

const Link = mongoose.model('Link', { url: String, clicks: Number })

const id = 'B12'
await Link.findByIdAndUpdate(id, { clicks: { $inc: 1 } })
```

The `$inc` operator accepts both positive and negative values. So it could also be used to decrement a value a shown below:

```javascript
await Link.findByIdAndUpdate(id, { clicks: { $inc: -1 } })
```
