Categories
JavaScript Answers

How to do batch insert with Node.js MongoDB Mongoose?

Spread the love

To do batch insert with Node.js MongoDB Mongoose, we call the insertMany method.

For instance, we write

const rawDocuments = [
  /* ... */
];

const mongooseDocuments = await Book.insertMany(rawDocuments);

to call the insertMany method in the Book schemas to insert the rawDocuments into the database.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *