Milen Pivchev
Milen Pivchev

Reputation: 1479

Unable to merge a Transaction set with SetOptions

I have to use a Transaction for setting and updating certain data in Firestore. I would like to merge new data if old data already exists. This is possible without transactions, but with them I can't seem to do it, even though it says you can.

From the Flutter Firestore implementation I can see the following doc:

/// Writes to the document referred to by the provided [DocumentReference].
/// If the document does not exist yet, it will be created. If you pass
/// SetOptions, the provided data can be merged into the existing document.
  Future<void> set(
  ///.....

I have Googled about the SetOptions class and it does exist in theory (https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/SetOptions) but I can't seem to find any Flutter example of it, and it doesn't seem to exist in the Flutter version of the lib, nor is it a parameter for this method.

This is my current transaction call:

  transaction.set(doc.reference, {
    "liked": FieldValue.arrayUnion([entryInfo.id]),
  });

Is it possible to do this in the Flutter version of Firestore or is it a mistake and it's not implemented yet?

Upvotes: 1

Views: 1073

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317750

Looking at the API documentation, it doesn't seem there is a variant of transaction.set() that accepts something similar to SetOptions. You might want to send feedback about this.

Upvotes: 1

Related Questions