Skip to content

Firestore - WriteBatch.Set ignoring {merge: true} when using FieldValue.increment #3045

@L1b3rtyy

Description

@L1b3rtyy

[REQUIRED] Describe your environment

  • Operating System version: _____ Windows 10
  • Browser version: _____ Chrome (latest Version 81.0.4044.129) but this seems irrelevant as it is not working in the emulator either
  • Firebase SDK version: _____ [email protected], @firebase/[email protected]
  • Firebase Product: _____ Firestore, Testing (auth, database, storage, etc)

[REQUIRED] Describe the problem

Updating a document with FieldValue.increment using a batch via the set function and the {merge: true} option fails. Looking at the logs it seems it is ignoring the option and trying to overwrite the document.

batch.update(somepath, {counter: firebase.firestore.FieldValue.increment(1)})
=> works as expected
batch.set(somepath, {counter: firebase.firestore.FieldValue.increment(1), {merge: true})
=> will reset counter to 1 whatever its previous value

https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue#increment
https://firebase.google.com/docs/firestore/manage-data/add-data#set_a_document
https://firebase.google.com/docs/reference/js/firebase.firestore.SetOptions

This is neither working in the emulator nor in Cloud Firestore.

Note that with the previous minor version [email protected], @firebase/[email protected] - it is all working fine

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions