---
description: Methods for document-based collections.
---

# DocumentBasedCollection

### `insert(document)`

Insert a document.

| Parameter | Description                                                                                                                                                          |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| document  | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The document to be written to the collection.</p> |

> returns [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
>
> Example:
>
> ```javascript
> accounts.insert({"email": "fir4tozden@gmail.com", "username": "fir4tozden", "password": "12345678", "region": "Muğla"});
> /*
>   {
>     "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
>     "_updated": false,
>     "_archived": false,
>     "_created_at": 2022-03-20T00:00:00.000Z,
>     "_created_timestamp": 1647745200000,
>     "email": "fir4tozden@gmail.com",
>     "username": "fir4tozden",
>     "password": "12345678",
>     "region": "Muğla"
>   }
> */
> ```

\


### `find(params, options)`

Find a document.

| Parameter        | Description                                                                                                                                                                                                                                                                             |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| params           | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The parameters you will use to find the data.</p> |
| options          | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> (optional)<br>Find options.</p>                                                                                                                                         |
| options.archived | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>Whether to find archived documents.</p>                                                                                                                 |

> returns [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
>
> Example:
>
> ```javascript
> accounts.find(document => document.email === "fir4tozden@gmail.com", {"archived": true});
> // or
> accounts.find({"email": "fir4tozden@gmail.com"}, {"archived": true});
> /*
>   {
>     "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
>     "_updated": false,
>     "_archived": false,
>     "_created_at": 2022-03-20T00:00:00.000Z,
>     "_created_timestamp": 1647745200000,
>     "email": "fir4tozden@gmail.com",
>     "username": "fir4tozden",
>     "password": "12345678",
>     "region": "Muğla"
>   }
> */
> ```

\


### `filter(params, options)`

Filter documents.

| Parameter        | Description                                                                                                                                                                                                                                                                               |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| params           | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The parameters you will use to filter the data.</p> |
| options          | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> (optional)<br>Filter options.</p>                                                                                                                                         |
| options.archived | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>Whether to filter archived documents.</p>                                                                                                                 |

> returns [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>
>
> Example:
>
> ```javascript
> accounts.filter(document => document.region === "Muğla", {"archived": true});
> // or
> accounts.filter({"region": "Muğla"}, {"archived": true});
> /*
>   [
>     {
>       "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
>       "_updated": false,
>       "_archived": false,
>       "_created_at": 2022-03-20T00:00:00.000Z,
>       "_created_timestamp": 1647745200000,
>       "email": "fir4tozden@gmail.com",
>       "username": "fir4tozden",
>       "password": "12345678",
>       "region": "Muğla"
>     },
>     {
>       "_id": "23ERK9fHqiH_n83fhzU7eOYtzz6tUl7S",
>       "_updated": false,
>       "_archived": false,
>       "_created_at": 2022-03-20T00:05:00.000Z,
>       "_created_timestamp": 1647734700000,
>       "email": "nehir@gmail.com",
>       "username": "nehir",
>       "password": "12345678",
>       "region": "Muğla"
>     }
>   ]
> */
> ```

\


### `has(params, options)`

Check if they have document.

| Parameter        | Description                                                                                                                                                                                                                                                                              |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| params           | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The parameters you will use to check the data.</p> |
| options          | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a> (optional)<br>Find options.</p>                                                                                                                                          |
| options.archived | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>Whether to has archived documents.</p>                                                                                                                   |

> returns [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
>
> Example:
>
> ```javascript
> accounts.has(document => document.region === "Muğla"); // -> true
> accounts.has({"region": "Muğla"}); // -> true
> ```

\


### `update(document_id, document)`

Update a document.

| Parameter    | Description                                                                                                                                                          |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| document\_id | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The ID of the document to be updated.</p>         |
| document     | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The document to be updated in the collection.</p> |

> returns [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
>
> Example:
>
> ```javascript
> let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
> accounts.update(document._id, {"email": "fir4tozden@gmail.com", "username": "hey_im_fir4tozden", "password": "87654321", "region": "İstanbul"});
> /*
>   {
>     "_id: "23ERK9fHqiH_n83fhzU7eOYtzz6tUl7S",
>     "_updated": true,
>     "_archived": false,
>     "_created_at": 2022-03-20T00:00:00.000Z,
>     "_created_timestamp": 1647745200000,
>     "_updated_at": 2022-03-20T00:10:00.000Z,
>     "_updated_timestamp": 1647735000000,
>     "email": "fir4tozden@gmail.com",
>     "username": "hey_im_fir4tozden",
>     "password": "87654321",
>     "region": "İstanbul"
>   }
> */
> ```

\


### `archive(document_id)`

Archive a document.

| Parameter    | Description                                                                                                                                                   |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| document\_id | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The ID of the document to be archived.</p> |

> returns [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
>
> Example:
>
> ```javascript
> let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
> accounts.archive(document._id); // -> true
> ```

\


### `unarchive(document_id)`

Unarchive a document.

| Parameter    | Description                                                                                                                                                     |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| document\_id | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The ID of the document to be unarchived.</p> |

> returns [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
>
> Example:
>
> ```javascript
> let document = accounts.find(document => document.email === "fir4tozden@gmail.com", {"archived": true});
> accounts.unarchive(document._id); // -> true
> ```

\


### `delete(document_id)`

Delete a document.

| Parameter    | Description                                                                                                                                                  |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| document\_id | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The ID of the document to be deleted.</p> |

> returns [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
>
> Example:
>
> ```javascript
> let document = accounts.find(document => document.email === "fir4tozden@gmail.com");
> accounts.delete(document._id); // -> true
> ```
