Jim*_*ane 5 firebase firebase-security google-cloud-firestore
现在我们在 firestore 上有了集合组查询!伟大的。
但是由于一些规则,如何通过Document ID查询集合组呢?
我试过:
return this.afs.collectionGroup('tokens', (ref) => {
return ref.where(firestore.FieldPath.documentId(), '==', `${this.afAuth.auth.currentUser.uid}`)
}).valueChanges();
Run Code Online (Sandbox Code Playgroud)
但我得到:
Invalid third parameter to Query.where(). When querying a collection group by FieldPath.documentId(), the value provided must result in a valid document path, but 'JKq2AFqGkkSLHsIVaXz4l3wwmfh1' is not because it has an odd number of segments (1).
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
return this.afs.collectionGroup('tokens', (ref) => {
return ref.where(firestore.FieldPath.documentId(), '==', `/users/JKq2AFqGkkSLHsIVaXz4l3wwmfh1`)
}).valueChanges();
Run Code Online (Sandbox Code Playgroud)
但后来我得到 0 个结果
我的代币集合文档 ID 基于我的/users/{userID}
我收集令牌的规则是:
match /{path=**}/tokens/{userID} {
allow read, write, create, update, delete: if request.auth.uid == userID;
}
Run Code Online (Sandbox Code Playgroud)
例如,这是我需要获得的文件
/suuntoAppAccessTokens/dimitrioskanellopoulos/tokens/JKq2AFqGkkSLHsIVaXz4l3wwmfh1
Run Code Online (Sandbox Code Playgroud)
当然如果我使用:
return this.afs.collectionGroup('tokens', (ref) => {
return ref.where(firestore.FieldPath.documentId(), '==', `/suuntoAppAccessTokens/dimitrioskanellopoulos/tokens/JKq2AFqGkkSLHsIVaXz4l3wwmfh1`)
}).valueChanges();
Run Code Online (Sandbox Code Playgroud)
它有效,但这击败了集合组查询的要点
那么有什么方法可以通过文档 ID 而不是路径 + 文档 id 来查询集合组呢?
| 归档时间: |
|
| 查看次数: |
512 次 |
| 最近记录: |