cachapa / firedart

A dart-native implementation of the Firebase Auth and Firestore SDKs
https://pub.dev/packages/firedart
Apache License 2.0
174 stars 62 forks source link

arrayUnion support for arrays #29

Open sjapps opened 4 years ago

sjapps commented 4 years ago

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 commented 4 years ago

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.

cachapa commented 4 years ago

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.

haleem13 commented 2 years ago

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

haleem13 commented 2 years ago

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

How to do this with firedart?????

puf commented 2 years ago

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.