Skip to content

Commit

Permalink
fix(mongodb): Ensure transactions are used properly in create (#2699)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jul 19, 2022
1 parent f886640 commit fe22615
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/mongodb/src/adapter.ts
Expand Up @@ -215,15 +215,18 @@ export class MongoDbAdapter<

return entry
}

const promise = Array.isArray(data)
? model
.insertMany(data.map(setId), writeOptions)
.then(async (result) =>
Promise.all(Object.values(result.insertedIds).map(async (_id) => model.findOne({ _id })))
Promise.all(
Object.values(result.insertedIds).map(async (_id) => model.findOne({ _id }, params.mongodb))
)
)
: model
.insertOne(setId(data), writeOptions)
.then(async (result) => model.findOne({ _id: result.insertedId }))
.then(async (result) => model.findOne({ _id: result.insertedId }, params.mongodb))

return promise.then(select(params, this.id)).catch(errorHandler)
}
Expand Down

0 comments on commit fe22615

Please sign in to comment.