I want to export data from firestore to googl sheets using Google Apps Script, I followed along this tutorial, and this is the code I used
function getFirestore(){
var email = "";
var key = "";
var projectId = "";
return FirestoreApp.getFirestore(email,key,projectId);
}
function myFunction() {
//1. Initialize variables
let firestore = getFirestore();
var activeSheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = activeSheet.getActiveSheet();
//2. Read documents from collection in Array
let allDocuments = firestore.getDocuments("Doctors");
//3. Iterate through the array items
for(var i = 0; i < allDocuments.length; i++){
//A. initialize Array to be printed to google sheet
var myArray = [];
// B. access columns
var name = allDocuments[i].fields["name"];
myArray.push(name.stringValue);
var major = allDocuments[i].fields["major"];
myArray.push(major.stringValue);
//C.write array as rows in google sheets
sheet.appendRow(myArray);
}
}
I also enabled google sheets API in google cloud
the problem is that I keep getting this error while running the code
Error
RangeError: Maximum call stack size exceeded
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
getFirestore @ Code.gs:1
Recognized by Google Cloud Collective
New contributor
fyry J4 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.