# Upsert

* A hybrid of update and insert operation.
*   Syntax

    > db.collection\_name.update({\<restriction query>}, {\<update query>}, {"upsert": true})
*   As shown in the above query syntax, upsert option enables us to do upsert operation, by default this option is false. ![Upsert](https://574639531-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJDnjsv52I3fJ56WbLgHu%2Fuploads%2Fgit-blob-777dab4f1174cb56dadd063ab731019819d91202%2FUpsert.png?alt=media)

    ```
        db.iot.updateOne(
            { 
                "sensor": r.sensor, "date": r.date, 
                "valcount": { "$lt": 48 } 
            },
            { 
                "$push": 
                    { "readings": 
                        { "v": r.value, "t": r.time } 
                    },
                    "$inc": 
                        { "valcount": 1, "total": r.value } 
            },
            { "upsert": true }
        )
    ```
