firedart icon indicating copy to clipboard operation
firedart copied to clipboard

arrayUnion support for arrays

Open sjapps opened this issue 5 years ago • 5 comments
trafficstars

Flutter firestore has something like this to add items to arrays

 Firestore.instance
   .collection('YourCollection')
   .document('YourDocument')
   .updateData({'array':FieldValue.arrayUnion(['data1','data2','data3'])});

Is this possible with this library yet?

The nodejs library also has the following (https://googleapis.dev/nodejs/firestore/latest/FieldValue.html)

image

sjapps avatar May 22 '20 20:05 sjapps

Here is how flutterfire implements it:

https://github.com/FirebaseExtended/flutterfire/blob/44e07cc2a0a8700a86290b383b03bc974c5d633a/packages/cloud_firestore/cloud_firestore/lib/src/field_value.dart

Those methods then call _CodecUtility. It looks like its using "FieldValueFactoryPlatform" which are platform specific so this may not be possible with rest api.

sjapps avatar May 22 '20 20:05 sjapps

I don't think this is currently possible (I'd have to test to be sure though).

It seems like some sort of advanced features that I don't expect most people to need. I wouldn't be against someone submitting a pull request for it but honestly if you need to do a lot of work with individual items in a list, you'd probably be better off just implementing it as a collection rather than an array inside a document.

cachapa avatar May 22 '20 21:05 cachapa

Hi I am facing the same problem is there anyone that could help me ????

haleem13 avatar Mar 25 '22 10:03 haleem13

Firestore.instance .collection('YourCollection') .document('YourDocument') .updateData({'array':FieldValue.arrayUnion(['data1','data2','data3'])});

How to do this with firedart?????

haleem13 avatar Mar 25 '22 10:03 haleem13

The arrayUnion operator in the Firebase SDKs maps to appendMissingElements. in the Firestore REST API. See https://firebase.google.com/docs/firestore/reference/rest/v1beta1/Write for more into.

puf avatar Aug 30 '22 06:08 puf