Flutterfire: [cloud_firestore] Not possible to merge set calls with Firestore transactions

Created on 13 Oct 2019  Â·  11Comments  Â·  Source: FirebaseExtended/flutterfire

Merging set calls using transactions is currently not possible in Flutter because we don't have a SetOptions class and parameter for the set() method.

However, the docs stay otherwise:

    /// 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(
      ///.....

Issue was also posted on StackOverflow: https://stackoverflow.com/questions/57202980/unable-to-merge-a-transaction-set-with-setoptions

Doctor

[√] Flutter (Channel stable, v1.7.8+hotfix.3, on Microsoft Windows [Version 10.0.17134.885], locale en-US)
    • Flutter version 1.7.8+hotfix.3 at C:\flutter
    • Framework revision b712a172f9 (2 weeks ago), 2019-07-09 13:14:38 -0700
    • Engine revision 54ad777fd2
    • Dart version 2.4.0


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\milen\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 32.0.1
    • Dart plugin version 182.5124
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[√] VS Code (version 1.36.1)
    • VS Code at C:\Users\milen\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.2.0

[√] VS Code, 64-bit edition (version 1.23.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.2.0

[√] Connected device (1 available)
    • INE LX1 • 5MG7N18829009925 • android-arm64 • Android 9 (API 28)

• No issues found!

crowd cloud_firestore missing-feature

Most helpful comment

I'm sure that the Flutter team has an abundance of important issues to address, but supporting all basic CRUD operations for the SDK's supported backend seems fundamental. Is there a plan for this?

All 11 comments

@mpivchev

The issue at https://github.com/flutter/flutter/issues/36950 has been closed and moved here. Future collaboration on this issue will be done here.

Same issue here! Any ETA?

Any updates on this? Also faced an issue.

Same problem here!!!

I'm sure that the Flutter team has an abundance of important issues to address, but supporting all basic CRUD operations for the SDK's supported backend seems fundamental. Is there a plan for this?

Looks like support is available in the document reference but not the set of the transaction. Tracking it as high-priority.

A dirty workaround for now would be to read the document contents and merge the data together inside of the set until this gets fixed - not ideal but until this gets fixed it's the only solution.

@Ehesp Could that merging workaround be implemented on the backend using the .onWrite() hook in a Cloud Function, since that function has both the pre and post versions of the document available to it?

Can the update operation be changed to support this case? Making it merge if existing, and creating if not present?

This is being sorted as part of https://github.com/FirebaseExtended/flutterfire/issues/2582

It'll also include merge and mergeFields.

Hey, as part of our on-going work for #2582, support for SetOptions on Transaction.set has been added in our Firebase Firestore rework (#2913) - which has now been merged into master. We'll look at publishing some prereleases in the next few days. Thank you

Was this page helpful?
0 / 5 - 0 ratings