# $upsert

| Name                                                     | Usage Type                                     | Description                                                                                                                                      |
| -------------------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| <mark style="background-color:green;">**$upsert**</mark> | <mark style="color:orange;">**Boolean**</mark> | <mark style="background-color:yellow;">**$upsert Operator Will Create Operators Like FindOneAndUpdate If The Entered Data Doesn't Exist**</mark> |

```javascript
/* Example Usage */
const model = ...Someone Model

(async () => {

await model.findOneAndUpdate({ classNumber: 999 },{ $set:{ name: "Five", surname: "So Beş" } },{ $upsert: true });
/*
{id:3, name: 'Five', surname: 'So Beş', age: null, classNumber: 999, achievements:[]},
*/

})();

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fivesobes.gitbook.io/cherry3/other-operators/filter-and-process-operators/usdupsert.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
