Firebase 如何使用flatter更新Firestore中的引用类型
我有一个包含两个字段的文档,一个是整数,一个是引用类型 主要 数值:10 参考:产品/9ci2hwiMUp63Q9Eugcqg 我想将字段ref更改为Firebase 如何使用flatter更新Firestore中的引用类型,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我有一个包含两个字段的文档,一个是整数,一个是引用类型 主要 数值:10 参考:产品/9ci2hwiMUp63Q9Eugcqg 我想将字段ref更改为products/guEgu2sjsyOsSEChu2fT。有一个类DocumentReference,唯一要更改的属性是路径,但为只读属性 我阅读了firebase.google.com中的文档,但没有关于如何更新这些类型的示例 是否可以更新此类型的字段?您可以在文档引用上使用UpdateData()来更新数据: DocumentReferenc
products/guEgu2sjsyOsSEChu2fT
。有一个类DocumentReference
,唯一要更改的属性是路径,但为只读属性
我阅读了firebase.google.com中的文档,但没有关于如何更新这些类型的示例
是否可以更新此类型的字段?您可以在文档引用上使用UpdateData()来更新数据:
DocumentReference ref = Firestore.instance.collection('products').document('guEgu2sjsyOsSEChu2fT');
Map<String,dynamic> data = {
'main value' : 10,
'ref' : ref, // Updating Document Reference
};
Firestore.instance.collection('Your Collection Name').document('your document name').updateData(data).whenComplete((){
print('Document Updated');
});
documentreferef=Firestore.instance.collection('products').document('guEgu2sjsyOsSEChu2fT');
地图数据={
“主值”:10,
“ref”:ref,//正在更新文档引用
};
Firestore.instance.collection('您的集合名称').document('您的文档名称').updateData(数据).whenComplete(){
打印(“文件更新”);
});
仅当类型为字符串时,此选项才有效。我得到了I/flatter(4535):引发了另一个异常:“String”类型不是“DocumentReference”类型支持的类型的子类型-检查引用类型。这是路径元素(集合、文档ID、集合、文档ID…)的真实引用,但我的问题与如何更新这种“数据类型”有关