如何查询AngularFire2/FireStore中的子集合?
我想查询的子集合中AngularFire2与没有成功公司的FireStore。已搜索,但没有找到合适的解决方案如何查询AngularFire2/FireStore中的子集合?
ngOnInit() {
// this does work
this.africaCollection = this.afs.collection('Country', ref => ref
.where('code', '==', 'za'));
this.countriesAfrica = this.africaCollection.valueChanges();
// this does not work
this.townCollection = this.afs.collection('Country').doc('za')
.collection('Towns');
this.towns = this.townCollection.valueChanges();
{
我的HTML看起来像这样:
<div>
<table>
<tr *ngFor="let town of towns | async">
<td>{{ town.name }}</td>
</tr>
</table>
</div>
我在这一个新手。
它可能与你的规则。
默认规则
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
更多关于规则的具体位置:
https://firebase.google.com/docs/firestore/security/secure-data#rules_dont_cascade
请确保您有该集合
您也可以将项目添加到项目你的收藏是通过代码来确定的它的位置正确。然后,您可以查看您的Firebase控制台,查看它放置的位置。
var town: Town = {
name: "town name",
region: "region name"
};
this.afs.collection('Country').doc('za').collection('Towns').add(town);
我设定的规则来服务cloud.firestore { 匹配/数据库/ {}数据库/文件{ 匹配/国家/ {}国家/镇/ {城市} { 允许读,写; }} } 我的第一个QRY运行,但第二个失败,权限错误 –
我已经更新了规则的例子。该版本仍然有权限错误吗?如果没有,还有其他错误? – Remi
谢谢。将尝试并发布结果。 –
你能用stackblitz.com重现问题?我可以帮助很多更用一个例子(我AngularFire的作者) –
大卫嗨 - 拥有使用stackblitz困难,但我已经把我在github上https://github.com/JacquesSchalkwyk/Firestore-Qry尝试。我希望这将有所帮助。目前我的数据库有默认的规则,每个人都可以读写。结构是Country-Towns-Listings –
当我将规则设置为:-service cloud.firestore match/databases/{database}/documents {0} {0} }} } 时 –