upsert¶
upsert=true makes update by id and replace by id insert a row when the id does not exist. Without it (the default, false), an unknown id changes nothing and answers data: null.
| Row 999 | What happens | Answer |
|---|---|---|
| exists | updated with the body | the row after the change |
| does not exist | inserted with customer_id: 999 and the body |
the new row |
- The inserted row is validated as a save : with a schema, every
requiredfield must be in the body. - Works on MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server and Oracle.
- With
returnDocument=beforeand an insert, the answer isnull: there was no row before. - From code :
g.sys.db.updateById({ ..., upsert: true }).