From e34f728139a1008503aa440f1b7cf6395719417b Mon Sep 17 00:00:00 2001 From: Beau Shaw Date: Fri, 28 Apr 2023 13:57:54 -0500 Subject: [PATCH] fix(mongodb): Speed up multi create (#3171) --- packages/mongodb/src/adapter.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/mongodb/src/adapter.ts b/packages/mongodb/src/adapter.ts index 7c8fb49adc..4461b5d52b 100644 --- a/packages/mongodb/src/adapter.ts +++ b/packages/mongodb/src/adapter.ts @@ -292,9 +292,7 @@ export class MongoDbAdapter< ? model .insertMany(data.map(setId), writeOptions) .then(async (result) => - Promise.all( - Object.values(result.insertedIds).map(async (_id) => model.findOne({ _id }, params.mongodb)) - ) + model.find({ _id: { $in: Object.values(result.insertedIds) } }, params.mongodb).toArray() ) : model .insertOne(setId(data), writeOptions)