# MongoDB - Prevent duplication in your arrays

When we want to insert data in an array in Mongo we use `$push` . But it won't prevent you **from inserting multiple times the same value in your array.**

If you want to ensure that there's no duplication.

You can use : `$addToSet`

### How it works

When you want to insert an element inside an array, `$addToSet` will check if this element already exists and if that's the case, will keep the existing one without pushing the element (but it will update your `updatedAt` field).

If your array doesn't exist yet, it will create and push the element inside it.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><code>$addToSet</code> work only on array field</div>
</div>
