I am trying to import JSON with 180k records. As you can see in this code, I can upload 500 records per run, but I need to upload a 180k record periodically.
What I am trying To Achieve:
- Parse JSON (DONE).
- Create a model from each JSON element (DONE)
- Upload this to Cloud Firestore (DONE BUT 500 DOCUMENT EACH)
Factory of Model:
factory Academician.fromJson(Map<String, dynamic> json) => Academician(
// Using this to parse data from JSON,
// rating and reviewList does not exist in JSON,
// that's why i need custom model
name: json["name"] ?? "",
designation: json["designation"] ?? "",
field: json["field"] ?? "",
universityName: json["university"] ?? "",
department: json["department"] ?? "",
rating: 0,
reviewList: [],
);
Parsing and uploading to Cloud Firestore:
parseJsonFromAssets('json/akademik_kadro.json')
.then((value) => value['Sayfa1'].forEach((value) {
academicianList.add(Academician.fromJson(value));
}))
.then((value) {
setState(() {
for (int z = 0; z < 500; z++) {
//500 is the single time upload limit to Cloud Firestore
//I guess
dbOperation.addToCollection(academicianList[z]);
}
});
});