Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need support to Update elements in an array in document in Cloud FireStore #20688

Closed
shashkiranr opened this issue Aug 16, 2018 · 10 comments
Closed
Labels
p: cloud_firestore Firebase Firestore plugin p: firebase Firebase plugins package flutter/packages repository. See also p: labels. waiting for PR to land (fixed) A fix is in flight

Comments

@shashkiranr
Copy link

Hi,

I could not update array in Cloud FireStore using flutter. Is there any workaround for this?

Currently I am retrieving all the array values and updating the array field. The updateData changes the entire array and not individual values. Need FieldValue.arrayUnion and FieldValue.arrayRemove support.

Eg code for Android - 

DocumentReference washingtonRef = db.collection("cities").document("DC");

// Atomically add a new region to the "regions" array field.
washingtonRef.update("regions", FieldValue.arrayUnion("greater_virginia"));

// Atomically remove a region from the "regions" array field.
washingtonRef.update("regions", FieldValue.arrayRemove("east_coast"));
Cloud Firestore Version
 cloud_firestore: ^0.7.4
flutter doctor -v
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.6 17G65, locale en-US)
    • Flutter version 0.5.1 at /Users/shashi/flutter
    • Framework revision c7ea3ca377 (3 months ago), 2018-05-29 21:07:33 +0200
    • Engine revision 1ed25ca7b7
    • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    • Android SDK at /Users/shashi/Library/Android/sdk
    • Android NDK at /Users/shashi/Library/Android/sdk/ndk-bundle
    • Platform android-28, build-tools 28.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 3.2 Preview.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b04)

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 27.1.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
@shashkiranr
Copy link
Author

Is there any workaround for this?

Anyone have any idea ?

@zoechi zoechi added plugin p: firebase Firebase plugins labels Aug 19, 2018
@zoechi
Copy link
Contributor

zoechi commented Sep 6, 2018

Looks like flutter/plugins#760 is supposed to fix that.

@zoechi zoechi added the waiting for PR to land (fixed) A fix is in flight label Sep 6, 2018
@zoechi
Copy link
Contributor

zoechi commented Oct 8, 2018

@shashkiranr this has landed. Is this still an issue?

@zoechi zoechi added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 8, 2018
@engintekin
Copy link

this looks fine to me, doesn't have the same update method though, flutter has an updateData method which is taking a map:

washingtonRef.updateData(
  {"regions", FieldValue.arrayUnion(["greater_virginia"])}
);

@no-response
Copy link

no-response bot commented Nov 7, 2018

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away!
Thanks for your contribution.
cc @Hixie

@no-response no-response bot closed this as completed Nov 7, 2018
@zoechi
Copy link
Contributor

zoechi commented Nov 7, 2018

doesn't have the same update method though

is this a problem?

@engintekin
Copy link

engintekin commented Nov 7, 2018

doesn't have the same update method though

is this a problem?

@zoechi for me this was not intuitive. If you look at the Update a document examples in this page, all the language examples are using docRef.update.

// Update an existing document
DocumentReference docRef = db.collection("cities").document("DC");

// (async) Update one field
ApiFuture<WriteResult> future = docRef.update("capital", true);

@zoechi
Copy link
Contributor

zoechi commented Nov 8, 2018

Ok, then lets reopen and let the plugin maintainer decide.

@zoechi zoechi reopened this Nov 8, 2018
@zoechi zoechi added this to the Goals milestone Nov 8, 2018
@no-response no-response bot closed this as completed Nov 8, 2018
@zoechi zoechi removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Nov 9, 2018
@flutter flutter deleted a comment from no-response bot Nov 9, 2018
@zoechi zoechi reopened this Nov 9, 2018
@zoechi zoechi added the p: cloud_firestore Firebase Firestore plugin label Jan 4, 2019
@kroikie kroikie closed this as completed Oct 13, 2019
@kroikie
Copy link

kroikie commented Oct 13, 2019

@shashkiranr

This issue has been moved to firebase/flutterfire#702. Any further collaboration will be done there.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: cloud_firestore Firebase Firestore plugin p: firebase Firebase plugins package flutter/packages repository. See also p: labels. waiting for PR to land (fixed) A fix is in flight
Projects
None yet
Development

No branches or pull requests

4 participants