Thank you, guys. I just noticed Prisma has nice documentation explaining the differences, and I missed it before raising this discussion:

https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#create-a-single-record-and-multiple-related-records

🌐
Prisma
prisma.io › home › crud › crud › crud › crud
CRUD (Reference) | Prisma Documentation
Quickstart with Prisma Postgres if you want a managed database to try these examples against quickly · The id is auto-generated. Your schema determines which fields are mandatory. const createMany = await prisma.user.createMany({ data: [ { name: "Bob", email: "bob@prisma.io" }, { name: "Yewande", email: "yewande@prisma.io" }, ], skipDuplicates: true, // Skip records with duplicate unique fields }); // Returns: { count: 2 } skipDuplicates is not supported on MongoDB, SQLServer, or SQLite.
Discussions

node.js - Prisma CreateMany Vs Transaction - Stack Overflow
To correct your last note re: performance - Prisma docs do state that: createMany uses a single INSERT INTO statement with multiple values rather than a single transaction. More on stackoverflow.com
🌐 stackoverflow.com
How to createMany with a relation? Looping CREATE and getting "too many connections"?
hello! Let me see if i got this straight - I have what i believe to be a very simple issue: I create a batch of reports scores I create a bunch of scores in the batch Because you can't use crea... More on github.com
🌐 github.com
3
5
CreateMany while connecting to many
Prisma does not support the createMany operation with nested writes, which includes the connect operation for relations. The createMany operation is designed to create multiple records in a single model without handling relations. More on github.com
🌐 github.com
1
1
Prisma CreateMany with a relation (connect)
Hi everyone, in Prisma is there a way to createMany with relation - using connect i assume? Basically this a million times: I read the documentation and there doesn't seem to be "nested createMany" but i think that's not that im doing (or is it? More on answeroverflow.com
🌐 answeroverflow.com
January 21, 2023
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
Nested readsRelation load strategies (Preview)ExamplesWhen to use which load strategy?Include a relationInclude all fields for a specific relationInclude deeply nested relationsSelect specific fields of included relationsRelation countFilter a list of relationsNested writesCreate a related recordCreate a single record and multiple related recordsUsing nested createUsing nested createManyCreate multiple records and multiple related recordsConnect multiple recordsConnect a single recordConnect or create a recordDisconnect a related recordDisconnect all related recordsDelete all related recordsDe
🌐
Medium
medium.com › @enayetflweb › prisma-crud-operations-guide-211a15113e70
Prisma CRUD Operations Guide. This guide will walk you through using… | by Md Enayetur Rahman | Medium
October 26, 2024 - import { PrismaClient } from '@prisma/client'; // Initialize Prisma Client const prisma = new PrismaClient(); const main = async () => { const createMany = await prisma.post.createMany({ data: [ { title: 'title1', content: 'content1', authorName: 'authorName1', }, { title: 'title2', content: 'content2', authorName: 'authorName2', }, { title: 'title3', content: 'content3', authorName: 'authorName3', } ] }); console.log(createMany); // Outputs the count of records created }; main();
🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
You cannot create or connect relations by using nested create, createMany, connect, connectOrCreate queries inside a top-level createManyAndReturn() query. See here for a workaround. When relations are included via include, a separate query is generated per relation. ... const users = await prisma.user.createManyAndReturn({ data: [ { name: "Sonali", email: "sonali@prisma.io" }, { name: "Alex", email: "alex@prisma.io" }, ], });
Find elsewhere
🌐
YouTube
youtube.com › prisma
Bulk Inserting Data with Prisma's createMany Method - YouTube
New at Prisma 2.16 is the createMany method. This method allows developers to bulk insert data instead of looping over a dataset and creating records one at ...
Published   February 5, 2021
Views   28K
Top answer
1 of 1
2

Hi @MatheusGNachtigall 👋

Thank you for raising this question.

Prisma does not support the createMany operation with nested writes, which includes the connect operation for relations. The createMany operation is designed to create multiple records in a single model without handling relations. See this section of the documentation.

However, you can use the create operation to create a single record along with its relations in a nested write. For example, to create a Post and connect it to existing Category records by their unique identifier, you would use the following code:

const createPostWithCategories = await prisma.post.create({
  data: {
    title: 'Post 1',
    categories: {
      connect: [{ id: 'category-id-1' }, { id: 'category-id-2' }],
    },
  },
});

In your case, since you want to create multiple posts and connect them to existing categories, you would need to loop through your postsData array and call prisma.post.create for each post. Here's an example of how you might do this:

async function createPostsAndConnectCategories(postsData) {
  return Promise.all(
    postsData.map(postData =>
      prisma.post.create({
        data: postData,
      })
    )
  );
}

const postsData = [
  {
    title: "Post 1",
    categories: {
      connect: [{ name: "Category1" }, { name: "Category2" }],
    },
  },
  {
    title: "Post 2",
    categories: {
      connect: [{ name: "Category2" }, { name: "Category3" }],
    },
  },
  // Add more posts as needed
];

const createdPosts = await createPostsAndConnectCategories(postsData);

This approach will execute the creation of each post and its connections to categories in parallel, which may help with performance compared to a sequential loop. However, it's important to note that this could still be a time-consuming operation given the large number of records you mentioned.

If this answers your question, it would be great if you could mark this Discussion as answered to indicate that it has been resolved.

Otherwise please let us know how else we can help you further or close the Discussion if it was resolved in some other way 🙏

🌐
SabinTheDev
sabinadams.hashnode.dev › basic-crud-operations-in-prisma
Prisma and TypeScript CRUD Basics - Sabin Adams
June 21, 2024 - That's exactly what createMany is for. This function is similar to the create function. The difference is that its data key takes in an array of Objects matching the model's type instead of a single object.
🌐
Answer Overflow
answeroverflow.com › m › 1066271029569278042
Prisma CreateMany with a relation (connect)
January 21, 2023 - const result = await prisma.posts.create({ data: { user: { connect: { id: user.id, }, }, ...postData, }, });
🌐
Oreate AI
oreateai.com › blog › beyond-single-entries-mastering-bulk-data-creation-with-prismas-createmany › 216aa35a372fb2de4a33691005710837
Beyond Single Entries: Mastering Bulk Data Creation With Prisma's `createMany` - Oreate AI Blog
March 4, 2026 - The core of createMany is the data field. Instead of a single object representing one record, you provide an array of objects. Each object in this array is just like the data you'd pass to a regular create call, defining the fields and values ...
🌐
Reddit
reddit.com › r/node › help with prisma create many.
r/node on Reddit: Help with Prisma create many.
October 28, 2021 -

I want to be able to use prisma createMany in a nested object. Is this possible? Basically a deck has many sets and sets have many cards. I want to be able to create this all at once.

Like this:

        const deck = await context.prisma.deck.create({
          data: {
            sets: { createMany: { data: [...newSets, cards: { createMany: {data: [...newCards]}}] } },
          },
        });
🌐
GitHub
github.com › prisma › prisma › issues › 5455
Create nested relations using `createMany()` and `createMany` · Issue #5455 · prisma/prisma
February 3, 2021 - kind/featureA request for a new feature.A request for a new feature.topic: createManynested `createMany`nested `createMany`topic: createMany()topic: nested write (create/update/delete)https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-writeshttps://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-writestopic: relations
Author   prisma
🌐
Medium
medium.com › @ivanspoljaric22 › mastering-bulk-inserts-in-prisma-best-practices-for-performance-integrity-2ba531f86f74
Mastering Bulk Inserts in Prisma: Best Practices for Performance & Integrity | by Ivan Spoljaric | Medium
February 14, 2025 - const data = [{ name: "A", ... }, { name: "B", ... }, ... ] const targetEntity = "..." // The name of a DB entity (table), defined in schema.prisma const records = await prisma.[targetEntity].createMany({ data }) const createdRecords = await prisma.[targetEntity].findMany({ where: { name: { in: data.map(item => item.name ) } } }); console.log(createdRecords) // [{ id: "1", ...
🌐
Medium
medium.com › @rsharma7_be22 › how-i-optimized-bulk-inserts-by-replacing-upsert-with-createmany-in-prisma-676fa74fb479
How I Optimized Bulk Inserts by Replacing .upsert with createMany in Prisma | by rohanS | Medium
July 30, 2025 - In a recent commit to my project getuplaced, I tackled a small but meaningful optimization: switching from repeatedly calling .upsert inside a Promise.all loop to a single createMany call. Let’s break down why this change makes sense and how it improved my code. Initially, I was iterating over an array of founders and running an upsert for each one: await Promise.all( founders.map((founder) => prisma.userFounderStatus.upsert({ where: { userId_founderId: { userId: user.id, founderId: founder.id, }, }, update: {}, create: { userId: user.id, founderId: founder.id, isSent: false, }, }) ) );
🌐
GitHub
github.com › prisma › prisma › issues › 8131
`createMany()` should return the created records · Issue #8131 · prisma/prisma
July 7, 2021 - The data to be created could be represented like so: Array<{post: PostData, comments: Array<CommentData>}>. If createMany returned the created data, I could do something like this: const inputs: Array<{post: PostData, comments: Array<CommentData>}> = [...]; const posts = prisma.post.createMany({data: [...]}); const commentCreateData = inputs.map((input, index) => input.comments.map((commentData) => ...))).flat(); prisma.comment.createMany({data: commentCreateData}); However, since createMany does not return the created data, it is difficult to create many posts and then create many comments linked to those posts in an efficient manner.
Author   prisma