如何将对象从数组推送到 angular 中的 firestore

How to push objects from an array to firstore in angular

我有一个 json 文件,我想将 json 文件中的所有对象推送到 firestore

这就是 json 的样子

[
   {
      "John":23m,
      "Mike":34m,
      "Adam":12m
   },
   {
      "John":45m,
      "Mike":45m,
      "Adam":67m
   },
   {
      "John":90m,
      "Mike":4m,
      "Adam":2m
   },
   {
      "John":23m,
      "Mike":3m,
      "Adam":1m
   },
   {
      "John":230m,
      "Mike":334m,
      "Adam":132m
   }
]

在我的 ts 文件中,我使用 http.get() 检索数据

public url='assets/data.json';
public rowData=[];

ngOnInit() {
    this.retrieve()
    .subscribe(data => this.rowData =data);
}


retrieve():Observable<DataInterface[]>{
    return  this.http.get<DataInterface[]>(this.url)
};

现在我想将 rowData 推送到 firestore

我试过这个:

uploadToFirestore(){
    return this.firestore.collections('data').add(this.rowData)
    //I got an error showing that I can't send Array to firestore 
}

有什么解决方法吗?

尝试从中创建一个对象,例如:

this.firestore.collections('data').add({ mydata: this.rowData });