2

I just figured out that in Flutter

List<int> values = [1,2,3,1,2,3];
Firestore.instance.path.updateData({"values": FieldValue.arrayUnion(values)});

results in the Firestore Array

(Firestore Array) [1,2,3]

Obviously the values are somehow mapped, removing duplicate values, although I can manually add duplicate values online in the Firebase panel (the datatype is called array respectively).

Is there a way to bypass this behaviour or is this a bug?

TheRuedi
  • 122
  • 1
  • 7

2 Answers2

2

According to the documentation here, array union will only add the elements that are not present. Because you're using a Firestore function intended to only add new unique values, it will behave that way without being bypassed. You can certainly bypass this function, though, but not without first calling the document, retrieving the array, and appending it before updating it to Firestore.

Thingamajig
  • 4,107
  • 7
  • 33
  • 61
-2

Use

List<int> values = [1,2,3,1,2,3];
Firestore.instance.path.setData({"values": values});

It works without using FieldValue.arrayUnion

TheRuedi
  • 122
  • 1
  • 7
  • It doesn't work, it say "The argument type Set can't be assigned to parameter type 'Map' I'm using flutter and my array is List – Hassan Ansari Dec 30 '19 at 10:27