> For the complete documentation index, see [llms.txt](https://moonlightdb.js.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moonlightdb.js.org/docs/collection/insertone.md).

# insertOne()

Inserts a single item into Database. If item passed in do not contain the \*\*\_id\*\* field, one will be added to each of the items missing it

## Example

```javascript
db.collection("users").insertOne({
    name: "username",
    banned: false,
    accountCreated: new Date().toLocaleDateString()
}).then(() => {
    //Item inserted in db;
    /*
        example output => {
            "_id": "31m16r2xrw85rp3gjq8fe7z6cdl10yuq",
            "name": "username",
            "banned": false,
            "accountCreated": "13/02/2023"
	}
    */
}).catch(error => {
    console.log("error:", error);
});
```

## insertOne(\<object>)

| Parameter                                                                                         | Description        |
| ------------------------------------------------------------------------------------------------- | ------------------ |
| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) | The item to insert |
