ios - Swift - Firestore 自动创建集合/文档
问题描述
有没有办法自动创建集合或文档?
就我而言,我已经有一个collection
(“用户”),其中包含所有用户。我想要实现的是,如果用户点击了几个按钮,并且还应该创建subcollections
一个空按钮。document
我试过这个但失败了:
func insertWish(){
let db = Firestore.firestore()
let userID = Auth.auth().currentUser!.uid
db.collection("users").document(userID).collection("wishlists").document("Main Wishlist").collection("Wünsche").document("Laptop").setData(["": ""]) { (error) in
if error != nil {
print("error")
}
}
}
这些集合/文档在我的数据库中不存在,只有在用户单击按钮时才应创建:
collection("wishlists").document("Main Wishlist").collection("Wünsche").document("Laptop")
解决方案
错误消息“The property.name is the empty string”告诉您您正在尝试添加无效文档:
setData(["": ""])
空字符串的字段名称无效。给它一个符合文档要求的名称。
推荐阅读
- javascript - 无法获取索引,返回了 NaN
- neo4j - 在 Neo4j 中显示关系
- jakarta-ee - 测试时是否可以更改@EJB 中的变量
- visual-studio-code - 如何在 VS 代码中为颤振项目创建备份 zip 文件
- python - TypeError:“列表”对象在尝试访问反向范围时不可调用
- python - 如何从sql结果打印结果?
- python - 如何使用 Matplotlib 创建双条形图或堆叠条形图
- python - 尝试使用 jupyter notebook 将 display(Math('f(x) = x + 2C')) 的输出保存到图像文件
- image - TinyMCE 图像插入插件是否可以查看缩略图预览?
- javascript - 如何查找选定元素或 ElementHandle 的后代元素?