【发布时间】:2021-04-09 16:31:21
【问题描述】:
作为项目的一部分,我们正在使用 Firestore,我们有一个食谱集合,其中包含三个子集合:成分、方法和 cmets。
我可以将数据写入一个子集合,但我似乎不知道如何将第二个子集合写入同一个文档。目前它会生成两个文档。一个是成分,另一个是方法。
我们正在生成从 firestore 生成的唯一 ID,我知道我需要使用该文档 ID,但我不知道该怎么做。在网上看,我只能看到如何写入一个子集合而不是两个。
FirebaseFirestore.instance.collection('recipe').add({}).then((response) {
print(response.id);
FirebaseFirestore.instance
.collection("recipe")
.doc(response.id)
.collection("ingredients")
.add({
"allergies": allergies,
"category": categoryValue,
"description": descriptionController.text,
"image": "testing",
"ingredients": ingredients,
"prepTime": prepTime,
"protein": proteins,
"servings": servingsController.text,
"title": recipeNameController.text
}).then((response) {
print(response.id);
FirebaseFirestore.instance
.collection("recipe")
.doc(response.id)
.collection("method")
.add({
"method": methodSteps
});
});
});
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore