Skip to content

Commit

Permalink
docstore/mongodocstore: fix error when calling the update function wi…
Browse files Browse the repository at this point in the history
…th no 'set' operations

This update modifies the newUpdateDoc function in the docstore/mongodocstore package to check the length of the 'sets' variable before adding the '$set' field to the 'updateDoc' map. This prevents an error when calling the update function with only 'unset' or 'inc' modifiers and no 'set' operations. This change improves the flexibility and robustness of the update function.

Resolves #3393
  • Loading branch information
bartventer committed Mar 2, 2024
1 parent 7750aa6 commit 11b07b1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docstore/mongodocstore/mongo.go
Expand Up @@ -416,7 +416,9 @@ func (c *collection) newUpdateDoc(mods []driver.Mod, writeRevision bool) (map[st
rev = driver.UniqueString()
sets = append(sets, bson.E{Key: c.revisionField, Value: rev})
}
updateDoc["$set"] = sets
if len(sets) > 0 {
updateDoc["$set"] = sets
}
if len(unsets) > 0 {
updateDoc["$unset"] = unsets
}
Expand Down

0 comments on commit 11b07b1

Please sign in to comment.