我在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}`)
);
}
请参阅相应的doc:https://firebase.google.com/docs/reference/js/firebase.firestore.FieldPath#.documentId
我相信无法查询对象是否存在。我认为你在对象中查询字段的想法可能是最好的选择。
您可以尝试查询date_modified字段以查找大于1900的任何内容。
getAllTenancyOffersByUserId() {
return this.afs.collection('collection_name', ref =>
ref.where(`
application.members.${this._auth.currentUserId}.date_modified`,
'>=',
new Date('1900-01-01')
),
);
}
实际上,你可以做的是过滤你在对象中的任何字符串字段,如下所示:
.collection("collectionName")
.where("mapArray.map.stringField", ">", "''")
这里重要的部分是字符串字段; “>”,“''”