Skip to content

Commit 6d5cc84

Browse files
fix(db-mongodb): updateOne mutates the data object and does not transform it for read (#13065)
Fixes #13045 `updateOne` when returning is `false` mutates the data object for write operations on the DB, but that causes an issue when using that data object later on since all of the id's are mutated to objectIDs and never transformed back into read id's. This fix ensures that the transform happens even when the result is not returned.
1 parent 34920a7 commit 6d5cc84

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

packages/db-mongodb/src/updateOne.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const updateOne: UpdateOne = async function updateOne(
5555
try {
5656
if (returning === false) {
5757
await Model.updateOne(query, data, options)
58+
transform({ adapter: this, data, fields, operation: 'read' })
5859
return null
5960
} else {
6061
result = await Model.findOneAndUpdate(query, data, options)

packages/db-mongodb/src/utilities/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export const transform = ({
417417

418418
if (operation === 'read') {
419419
delete data['__v']
420-
data.id = data._id
420+
data.id = data._id || data.id
421421
delete data['_id']
422422

423423
if (data.id instanceof Types.ObjectId) {

0 commit comments

Comments
 (0)