Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift-Firestore自动创建收藏/文档_Ios_Swift_Firebase_Google Cloud Firestore - Fatal编程技术网

Ios Swift-Firestore自动创建收藏/文档

Ios Swift-Firestore自动创建收藏/文档,ios,swift,firebase,google-cloud-firestore,Ios,Swift,Firebase,Google Cloud Firestore,有没有办法自动创建集合或文档 在我的例子中,我已经有了一个集合(“用户”),其中包括所有的用户。 我想实现的是,如果用户单击按钮,则应该创建几个子集合,同时创建一个空的文档 我尝试过这个,但失败了: func insertWish(){ let db = Firestore.firestore() let userID = Auth.auth().currentUser!.uid db.collection("users").document(userID).collec

有没有办法自动创建集合或文档

在我的例子中,我已经有了一个
集合
(“用户”),其中包括所有的用户。
我想实现的是,如果用户单击按钮,则应该创建几个
子集合
,同时创建一个空的
文档

我尝试过这个,但失败了:

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")
错误消息“property.name为空字符串”告诉您正在尝试添加无效文档:

setData(["": ""])

空字符串的字段名无效。给它一个符合中要求的名称。

什么是失败的?是否有错误消息?您希望代码具体做什么?集合/文档不会被创建,它会打印“错误”消息错误是什么?变量
错误
。它会告诉你怎么了。哦,我忘了!这就是错误:可选(“property.name是空字符串。”)修复了这个问题,谢谢:)但是在我创建了这样一个文档之后,还有另一个问题。如果你能看一下@DougStevenson Answer,有没有办法创建一个空文档?
setData([])
而现在没有实际工作的fieldsok。但在创建的文档中,Firestore内部会显示该文档“不可用”,并且不会显示在快照或查询中。如果不添加任何字段,则不会有可以找到它的查询。您可以
获取该文档,但无法搜索。如果您有后续问题,请单独发布。评论不适合继续提问。