> 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/insertmany.md).

# insertMany()

Inserts an array of items into database. If items passed in do not contain the \*\*\_id\*\* field, one will be added to each of the items missing it

## Example

```javascript
db.collection("users").insertMany([
	{a: "123"},
	{b: "456"},
	{c: "789"}
]).then(() => {
    //Items inserted in db;
    /*
    	example output => [
    		{
    			"_id": "m0i1s85b9cui2qr4ys8bqvl8wczr51em",
			"a": "123"
		},
		{
			"_id": "1n608o008q24ul39ssyqniq5b9i33cx7",
			"b": "456"
		},
		{
			"_id": "3cfp5p75x5vi1hk9cly140zgy1fs50g7",
			"c": "789"
		}
	]
    */
}).catch(error => {
    console.log("error:", error);
});
```

## insertMany(Array\<Object>)

| Parameter                                                                                                                                                                                          | Description         |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| [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)> | The items to insert |
