是否有正确的方法将相同的数据文档添加到 firestore 中的两个不同集合中?
Is there a correct way to add same data documents into two different collections in firestore?
以下代码将数据插入 firestore 中的 'doctors' 集合。但是我想将相同的数据记录同时添加到同一个 firestore 数据库中另一个名为 'next' 的集合中。
service.ts
create_Newdoctor(Record){
return this.firestore.collection('doctors').add(Record);
}
component.ts
CreateRecord(docForm: NgForm){
let Record = {};
Record['fullName']=this.fullName;
Record['email']=this.email;
Record['gender']=this.gender;
Record['role']="doctor";
this.DoctorService.create_Newdoctor(Record).then(res=> {
this.fullName="";
this.email="";
this.gender="";
console.log(res);
this.message = "New doctor added";
}).catch(error=>{
console.log(error);
});
}
能不能提前告诉我一个办法this.Thank你
const collections = ["doctors", "next"];
create_Newdoctor(Record, collections) {
const promises = collections.map(collectionName =>
this.firebase.collection(collectionName).add(Record)
);
return Promise.all(promises);
}
以下代码将数据插入 firestore 中的 'doctors' 集合。但是我想将相同的数据记录同时添加到同一个 firestore 数据库中另一个名为 'next' 的集合中。
service.ts
create_Newdoctor(Record){
return this.firestore.collection('doctors').add(Record);
}
component.ts
CreateRecord(docForm: NgForm){
let Record = {};
Record['fullName']=this.fullName;
Record['email']=this.email;
Record['gender']=this.gender;
Record['role']="doctor";
this.DoctorService.create_Newdoctor(Record).then(res=> {
this.fullName="";
this.email="";
this.gender="";
console.log(res);
this.message = "New doctor added";
}).catch(error=>{
console.log(error);
});
}
能不能提前告诉我一个办法this.Thank你
const collections = ["doctors", "next"];
create_Newdoctor(Record, collections) {
const promises = collections.map(collectionName =>
this.firebase.collection(collectionName).add(Record)
);
return Promise.all(promises);
}