具有Flutter的FieldValue arrayUnion和Cloud FireStore [英] FieldValue arrayUnion and Cloud FireStore with Flutter
问题描述
我有这样的云火存储对象
I have cloud fire store object like this
"TestCollection" : ["Test1","Test"]
现在我要使用FieldValue.arrayUnion更新此数组因为如果元素相同,那么我不想做任何事情,但是如果不是,那么我想添加元素
Now I want to update this array with FieldValue.arrayUnion because if element is same then i don't want to do anything but if it is not then I would like to add element
docRef.updateData({"TestCollection":FieldValue.arrayUnion(["test"])})
但是此语句给出了错误,例如对象不能具有嵌套数组
but this statement gives the error like object can not have nested array
任何人都可以帮助或提供类似的示例来查找语法吗?
Can anyone please help or provide same kind of example to have look for syntax ?
推荐答案
我找到了一个解决方案.试试这个:
I have found a solution. Try this:
Firestore.instance
.collection('YourCollection')
.document('YourDocument')
.updateData({'array':FieldValue.arrayUnion(['data1','data2','data3'])});
如果仍然无法正常运行,请尝试更新您的Firebase.
If it still doesn't work, try to update your Firebase.
首先打开一个提取到您的flutter项目的终端,然后:
First open a terminal fetched to your flutter project, then:
cd ios
pod update Firebase
此解决方案仅适用于mac用户.
This solution is only for mac users.
这篇关于具有Flutter的FieldValue arrayUnion和Cloud FireStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!