【发布时间】:2019-11-10 08:30:36
【问题描述】:
我正在尝试做一个“小技巧”来避免每次页面加载时都阅读用户文档。所以我将它保存在本地,每次加载页面时,我都会获取本地版本,获取updated_at 属性,然后执行WHERE last_updated > {{updated_at}} 之类的操作。为此,我想使用这个:
firebase.firestore().collection('User')
.where(firebase.firestore.FieldPath.documentId(), '==', firebase.auth().currentUser.uid)
.where('updated_at', '>', updated_at)
.get()
如您所见,我有一个等式 (==) 和一个不等式 (>)。为什么我在控制台上会出现以下错误:
FirebaseError: Cannot have inequality filters on multiple properties: updated_at
at new t (https://www.gstatic.com/firebasejs/6.0.2/firebase-firestore.js:1:47054)
at t.fromRpcStatus (https://www.gstatic.com/firebasejs/6.0.2/firebase-firestore.js:1:116660)
at t.fromWatchChange (https://www.gstatic.com/firebasejs/6.0.2/firebase-firestore.js:1:125914)
at t.onMessage (https://www.gstatic.com/firebasejs/6.0.2/firebase-firestore.js:1:242411)
at https://www.gstatic.com/firebasejs/6.0.2/firebase-firestore.js:1:241212
at https://www.gstatic.com/firebasejs/6.0.2/firebase-firestore.js:1:241997
at https://www.gstatic.com/firebasejs/6.0.2/firebase-firestore.js:1:144869
如果本地版本与数据库中的版本相同,我这样做是为了避免从数据库中读取。如果您有更好的方法,请告诉我。
谢谢
【问题讨论】:
-
firebaser here 我刚刚在jsbin.com/zexapuv/edit?js,console 中重现了这种行为,并询问为什么这些过滤器会触发该错误。我唯一能想到的是
documentId()有点特殊,但在这种情况下,我希望得到关于该字段的更明确的错误消息。
标签: javascript firebase google-cloud-firestore