【问题标题】:Swift/Firestore/Cloud Functions - Send message to a random userSwift/Firestore/Cloud Functions - 向随机用户发送消息
【发布时间】:2019-03-07 07:28:20
【问题描述】:

我可以在 Firestore 中发送创建文档,但我想知道是否有办法从 swift 或 Cloud Functions 中的 typescript 中将数组中的 n 个用户 ID/用户文档 ID 添加到该文档.

我知道我可以查询并从数组中的用户集合中获取所有用户,然后让 n 个随机用户添加到要在 Firestore 中创建的文档中,但如果我有一百万用户,那将是百万阅读,我试图避免这种情况。

代码

    if let data = self.imageView.image?.pngData() {
        let postID = APIs.posts.collection.document()
        Services.storage.upload(path: "posts/\(postID).png", data: data, onSuccess: { (url) in
            Services.crud.create(
                ref: APIs.posts.collection.document(),
                dict: [
                    "createdAt": Date(),
                    "fromUser": APIs.users.currentUserRef,
                    "post": url,
                    "timer": 5,
                    //"toUsers": [userID1, userID2, userID3, etc...] <- How I want to end up in Firestore
                    "type": "Image"
                    ] as [String: Any],
                onSuccess: {
                    self.openCamera()
            }) { (error) in
                print(error)
            }
        }) { (error) in
            print(error)
        }
    }

【问题讨论】:

    标签: swift typescript google-cloud-firestore google-cloud-functions


    【解决方案1】:

    如果您想知道集合中文档的所有 ID,您仍然需要查询整个集合以获取所有 ID。 Firestore 中没有免费的“获取所有 ID”操作。没有找到随机选择的文档的操作。

    【讨论】:

    • 好吧,这就是我的假设。只是想我会问。谢谢!我只需要找到一个完整的工作,啊哈。
    • 您需要自己编写解决方案。尝试搜索“实时数据库”而不是 Firestore 以获得类似的解决方案,因为它们都是具有类似限制的 NoSQL 数据库。
    猜你喜欢
    • 2020-05-26
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 2018-11-04
    • 2016-09-20
    • 2018-02-22
    • 1970-01-01
    • 2019-06-27
    相关资源
    最近更新 更多