2

I'm currently working on a Xamarin application in iOS and Android that uses Firebase. I'm trying to add a value to an existing array in firestore. In iOS I had no problems using FieldValue.FromArrayUnion(obj). However in Android I'm having a hard time since this method does not exist. Any ideas of how can I add a value into my array without overwriting its data?

Thank you.

SDj
  • 57
  • 5
  • I'm using Native. – SDj Feb 04 '19 at 16:18
  • Ah... yes, ArrayUnion and ArrayRemove are missing from the auto binding (they need to add them manually due to the parameter type, should be reported as a bug). You can call those static methods via some JNI code from C#. – SushiHangover Feb 04 '19 at 16:34
  • Thanks for your answer. Can you give me some additional directions on how to do that? – SDj Feb 04 '19 at 16:48
  • I looked at the arr that xamarin bund and Xamarin is way behind on the bindings versions of FireStore... I added an answer... – SushiHangover Feb 04 '19 at 18:43
  • How you have done this in iOS? Please check my query https://stackoverflow.com/questions/67003663/how-to-update-elements-in-an-array-of-firestore-document-using-xamarin-ios – Divyesh Apr 09 '21 at 05:00

1 Answers1

2

Xamarin has not released a nuget package version that is binding the Firestore version that added FieldValue.arrayUnion and FieldValue.arrayRemove. Those were added in 17.0.5 and the latest version of 18.0.0, so Microsoft is a number of major/minor versions behind.

Cloud Firestore version 17.0.5

Added FieldValue.arrayUnion() and FieldValue.arrayRemove() to atomically add and remove elements from an array field in a document.

Thus the arrayUnion and arrayRemove static methods are missing in

id="Xamarin.Firebase.Firestore" version="60.1142.1"

Building that binding project from source would be your fastest option:

Community
  • 1
  • 1
SushiHangover
  • 73,120
  • 10
  • 106
  • 165