# How to insert multiple items at once in a MongoDB collection

> Learn how to insert multiple items at once into a MongoDB collection from Node.js by passing an array of objects to the insertMany() method.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-10-28 | Topics: [Database](https://flaviocopes.com/tags/database/) | Canonical: https://flaviocopes.com/mongodb-insert-multiple-items/

I had the need to insert multiple items at once in a [MongoDB](https://flaviocopes.com/mongodb/) collection, from a [Node.js](https://flaviocopes.com/nodejs/) application

Here's what I did:

```js
const mongo = require('mongodb').MongoClient
const url = 'mongodb://localhost:27017'
let db, jobs

mongo.connect(
  url,
  {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  },
  (err, client) => {
    if (err) {
      console.error(err)
      return
    }
    db = client.db('myapp')
    jobs = db.collection('jobs')

    const data = [{...}, {...}]
    jobs.insertMany(data)
  }
)
```

Given an array of objects, I called `insertMany()` on the collection I wanted to populate.
