[英]Is there a way I can add data to parent document and child document of a collection in firestore?
I'm working on e-commerce for my college project.我正在为我的大学项目从事电子商务。 I have a Parent collection of 'Products' and inside 'Products' collection I have documents of the different company name.
我有一个“产品”的父集合,在“产品”集合中我有不同公司名称的文档。 Inside Company document I have created Collection of Categories likes vegetables, pastries etc.
在公司内部文件中,我创建了蔬菜、糕点等类别的集合。
I want to add the address key-value pair to the company name document.我想将地址键值对添加到公司名称文档中。 In a single query.
在单个查询中。 To do this right now I'm using This query.
为此,我现在正在使用此查询。
await firestoreInstance
.collection("Products")
.document(_productCompany.toUpperCase())
.setData({"data": ""}).then((value) => firestoreInstance
.collection("Products")
.document(_productCompany.toUpperCase())
.collection(_productCategory)
.document(_productCategory +
" " +
_productCompany +
" " +
_productName)
.setData({
"DownloadUrl": "$_downloadURL",
"CategoryName": "$_productCategory",
"CompanyName": "$_productCompany",
"ProductName": _productName,
"PricePerQuantity": _productPricePerQuantity,
"Available": true,
"itemQuantityToCart": 0
}));
Is there a way I can do It In a single query?有没有办法在单个查询中完成它?
If you have two documents to update (regardless of their relationship to each other), you will need to update them separately.如果您有两个文档要更新(无论它们之间的关系如何),则需要分别更新它们。 There aren't any shortcuts for this.
这没有任何捷径可走。
If you want to update two documents atomically (at the same time), then you can do a batch write to commit both changes simultaneously.如果您想以原子方式(同时)更新两个文档,那么您可以进行批量写入以同时提交两个更改。 But you will still have to generate two document references and specify the data those documents should contain.
但是您仍然需要生成两个文档引用并指定这些文档应包含的数据。
You can read more about this specifically for Flutter here .您可以在此处阅读有关 Flutter 的更多信息。 The entry point for a batch write starts with the batch() method.
批量写入的入口点从batch()方法开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.