6 Replies
Just add an array as a field to a document you want to insert into your db. See: https://docs.convex.dev/database/types#convex-values
and
https://docs.convex.dev/database/writing-data#inserting-new-documents
Writing Data | Convex Developer Hub
Mutations can insert, update, and
Data Types | Convex Developer Hub
All Convex documents are defined as Javascript objects. These objects can have
Sorry i wan't clear enough, what i wanted to do was insert many documents in a table at the same time, but already found a solution. Thanks
Struggling with the same issue (inserting a document for each item in an array) and found this in search - any pointers on where to go with this?
Current code:
objects
is an array of objects who match the shape of my "reports" schema (minus the storageId that I'm inserting), and I'd like to create a new document for each object but when I try to insert them like this I'm getting a TS error:
An array of Promises may be unintentional. Consider handling the promises' fulfillment or rejection with Promise.all or similar, or explicitly marking the expression as ignored with the
void operator.eslint@typescript-eslint/no-floating-promises
@Nekeohloss
you should wrap your map in a Promise.all. That way, it'll wait for all the inserts to complete before moving on
try this:
await Promise.all(
objects.map((obj) =>
ctx.db.insert("reports", { storageId: storageId, ...obj })
)
);
Ah that did it, thanks! I was so stuck on it being something particular to Convex that I missed what the message was actually saying 😅
totally. happens to the best of us. glad its sorted!👍