【发布时间】: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