【问题标题】:Cloud Firestore Nested arrays are not supported Error Flutter不支持 Cloud Firestore 嵌套数组 Error Flutter
【发布时间】:2021-03-10 16:27:01
【问题描述】:
我正在尝试将 json 导入到包含嵌套数组的云 Firestore 集合中,但即使 FieldValue.arrayUnion 函数出现错误“无效数据。不支持嵌套数组”。
FirebaseFirestore.instance
.collection('universities2')
.doc(value.docs.first.id)
.update({
'departments': FieldValue.arrayUnion([
json["Sayfa1"][0][x]["department"][0]["name"],
json["Sayfa1"][0][x]["department"][0]["fields"]
])
});
有什么方法可以实现吗?
【问题讨论】:
标签:
firebase
flutter
google-cloud-firestore
【解决方案1】:
在node.js 中使用扩展运算符(...) 或.apply(this, array) 正在工作,例如:
FirebaseFirestore.instance
.collection('universities2')
.doc(value.docs.first.id)
.update({
'departments': FieldValue.arrayUnion(...[
json["Sayfa1"][0][x]["department"][0]["name"],
json["Sayfa1"][0][x]["department"][0]["fields"]
])
});
或
FirebaseFirestore.instance
.collection('universities2')
.doc(value.docs.first.id)
.update({
'departments': FieldValue.arrayUnion.apply(this, [
json["Sayfa1"][0][x]["department"][0]["name"],
json["Sayfa1"][0][x]["department"][0]["fields"]
])
});