这是我的数据库 I have a users collection with documents as each user
问题是,每当我使用实际的数据库编辑工具更改字段时,我的应用程序都无法访问数据
当我查询这些字段时,会得到编辑之前的数据
if let document = document {
if let username = document.get("user_username") as? String,
let action = document.get("status") as? String,
let description = document.get("status_desc") as? String,
let companion = document.get("user_username") as? String {
ViewController.myName = username
self.helloLabel.text = username + " "
self.actionArray.append(action)
self.actionArray.append(description)
self.actionArray.append(companion)
} else {
print("missing fields in the status")
}
} else {
print("Document does not exist in cache")
}
}
当我现在打印状态字段时,我得到了之前没有在“睡眠中”的字符串
我也很困惑,因为当我通过应用程序本身更新字段时,数据库看起来完全一样,但是应用程序能够检测到更改并显示新字段
有人可以解释为什么会发生这种情况,或者我将如何解决此问题
答案 0 :(得分:0)
设置一个侦听器以接收数据更改事件,以便使用onSnapshot()方法而不是get()侦听文档的实时更改。
每次内容更改时,侦听器都会收到数据的初始快照和另一个快照。
链接: