【问题标题】:Query inner object id in a collection using Firestore/ Angularfire2 or Firestore SDK使用 Firestore/Angularfire2 或 Firestore SDK 查询集合中的内部对象 ID
【发布时间】:2018-06-27 07:59:57
【问题描述】:

你能告诉我如何查询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;
}

火库:

【问题讨论】:

    标签: angular typescript ionic3 angularfire2 google-cloud-firestore


    【解决方案1】:

    这就是解决方案。我们可以简单地如下图所示。 .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)
        );
      } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 2019-01-16
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多