首页 文章

使用Firestore / Angularfire2或Firestore SDK查询集合中的内部对象ID

提问于
浏览
0

你能告诉我如何在 budgets 集合中查询 budgetGroup 对象的 id 吗?

我可以像下面这样做一个基本的查询 . 但是如何查询上面提到的内部对象呢?

provider.ts

getSpecificBudget(id:string;budgetGroup: BudgetGroup, projectId: string): AngularFirestoreCollection<Budget> {
    return this.fireStore.collection<Budget>(`projects/${projectId}/budgets`, ref => ref
      .where('id', '==', id)
    );
  }

model.ts

export class Budget {
    id: string;
    amount: number;
    contingency: number = 20;
    budgetGroup: BudgetGroup = new BudgetGroup();
    creationTime: string;
}

export class BudgetGroup {
    id: string;
    name: string;
    creationTime: string;
}

公司的FireStore:

enter image description here

1 回答

  • 2

    这是解决方案 . 我们可以简单地如下所示 . 即 .where('budgetGroup.id', '==', budgetGroup.id)

    getSpecificBudgetGroupBudget(budgetGroup: BudgetGroup, projectId: string): AngularFirestoreCollection<Budget> {
        return this.fireStore.collection<Budget>(`projects/${projectId}/budgets`, ref => ref
          .where('budgetGroup.id', '==', budgetGroup.id)
        );
      }
    

相关问题