Car*_*lez 8 javascript firebase google-cloud-firestore
我正在尝试做一个“小技巧”以避免每次页面加载时都阅读用户文档。所以我将它保存在本地,每次加载页面时,我都会获取本地版本,获取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()
Run Code Online (Sandbox Code Playgroud)
如您所见,我有一个等式 ( ==
) 和一个不等式 ( >
)。为什么我在控制台上收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
如果本地版本与数据库中的版本相同,我这样做是为了避免从数据库中读取。也许如果您有更好的方法,请告诉我。
谢谢
火力士在这里
您进行的相等性检查在documentId()
Firestore 内部转换为范围检查,因为键存储为现有索引中的最后一项(如果我理解正确的话)。这意味着您在服务器端尝试执行两次不等式/范围检查,这是不允许的。
所以你看到的行为是正确的。但这绝对不直观,错误信息也没有帮助。我们将寻找一种通过检测这种组合来改进错误消息的方法。
归档时间: |
|
查看次数: |
3644 次 |
最近记录: |