我有两个数据收集
Collection1 = Companies (List of companies)
ID
..
Collection2 = TH(List of summary Transaction History)
ID
基本上,它们都具有相同的ID(公司ID),我正在尝试将每个公司及其在(TH)中的伴随记录合并,然后将其输出到表中。
谷歌搜索很多,但没有帮助。
我的代码(companies.services.ts)
export class CompanieService {
companiesCollection: AngularFirestoreCollection <Company>;
thv4CLcollection: AngularFirestoreCollection <THv4CL>;
Thv4: AngularFirestoreDocument <THv4CL>;
companies: Observable<Company[]>;
Thv4C: Observable<any[]>;
constructor(public fs: AngularFirestore) {
this.companiesCollection = fs.collection<Company>('companies', ref =>
ref.orderBy('companyName'));
this.thv4CLcollection= fs.collection<THv4CL>('transactionHistory', ref =>
ref.orderBy('companyName'));
//const res = await Promise.all(clients);
this.companies = this.companiesCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
var data = a.payload.doc.data() as Company;
const id = a.payload.doc.id;
this.fs.doc('transactionHistory/' + id).valueChanges().pipe(
map(data2 =>
Object.assign({}, {
id, ...data, ...data2
})));
return { id, ...data };
}))
);
}
我也尝试过
this.companiesCollection = fs.collection<Company>('companies', ref =>
ref.orderBy('companyName'));
this.companies = this.companiesCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as Company;
const id = a.payload.doc.id;
// console.log("company "+data.companyName);
this.fs.collection<THv4CL>("transactionHistory").doc(data.identifier)
.snapshotChanges().pipe( map(data2 =>
{
console.log("Thv4CL "+data2);
data.thCL=data2.payload.data() as THv4CL;
}));
return { id, ...data, };
}))
);
我尝试遍历并获取所有公司的列表,但未与其他系列一起加入。