javascript - 按对象键查询 Firestore
问题描述
我在firestore的集合中有一系列嵌套对象,它们有一个UID的键。我想通过检查他们的 UID 是否是对象键(基本上是否存在)来查询与用户相关的所有文档。这是firestore中的模型:
这就是我目前尝试返回文件的方式:
getAllTenancyOffersByUserId() {
return this.afs.collection('collection_name', ref =>
ref.where(`application.members.${this._auth.currentUserId}`, '==', !null),
);
}
但这什么也没返回。我知道我可以通过该状态进行查询,但是它会不断更新,因此会导致问题
解决方案
以下应该可以解决问题:
getAllTenancyOffersByUserId() {
return this.afs.collection('members', ref =>
ref.where(firebase.firestore.FieldPath.documentId(), '==', `${this._auth.currentUserId}`)
);
}
请参阅相应的文档:https ://firebase.google.com/docs/reference/js/firebase.firestore.FieldPath#.documentId
推荐阅读
- python - 如何在 Elasticsearch 服务器前创建 Flask REST API?
- javascript - 如何在 Chrome 上请求用户对音频的许可?
- python - Python tzinfo=pytz.utc 关于现有时间
- java - 将大字节数组转换为双变量中的自然数
- python - 为什么我们需要在登录后从客户端为每个 API 发送 JWT,因为 DRF 在 settings.py 中登录后维护 isAuthenticated 标志?
- excel - Sub 的限定符无效
- html - 如何使用html中的注销按钮在网站主页的导航栏中添加图像
- git - Git push 在推送后显示我不相关的文件夹
- java - 如何修复 IndexOutOfBoundsException 问题
- r - R:在数据框中获取匹配表情符号对的频率时遇到问题