簡體   English   中英

使用Firestore / Angularfire2或Firestore SDK查詢集合中的內部對象ID

[英]Query inner object id in a collection using Firestore/ Angularfire2 or Firestore SDK

您能告訴我如何在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)
    );
  }

模型

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;
}

消防站:

在此處輸入圖片說明

這是解決方案。我們可以簡單地如下所示。 .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)
    );
  } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM