我正在尝试使用 Firebase firestore 数据库构建“时间敏感”应用程序。我一直坚持从 Firestore 获取当前时间戳。一种解决方案是存储firebase.firestore.FieldValue.serverTimestamp() 然后再次读取它,但我最终会在每次数据库读取时至少进行一次顺序写入和一次读取。我一直在这里找到对函数 GetReadTime() 的引用:stackoverflow 答案建议它 和这里: firestore 文档?如果它有效,它将解决我的问题,但根据我的经验,这个函数在文档上不存在,也不存在 querySnapshot。
我努力了:
function loadTasks() {
db.collection("tasks_"+firebase.auth().currentUser.uid)
//.orderBy("clientSideFinish")
.onSnapshot(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
renderTask(doc);
console.log(doc.getReadTime());
console.log(doc.GetReadTime());
});
console.log(querySnapshot.getReadTime());
console.log(querySnapshot.GetReadTime());
});
}
并且所有控制台日志抛出功能不存在异常。