How can I get array data formatted into google sheets so I can import it into firestore? See imagee below. I have a script to import data from Google sheets directly into my Firestore but I don't know how to format an array with string items like the image below. What is the best way to do this in Google sheets/data format?
// Create a menu item for 'Export to Firestore'
function onOpen() {
SpreadsheetApp.getUi().createMenu('?? Firebase').addItem('Export to Firestore', 'main').addToUi();
}
function main() {
// Get the active spreadsheet and its name for the collection name
var sheet = SpreadsheetApp.getActiveSheet();
var sheetName = sheet.getName();
// Get the first row as object properties
// [ 'comment', 'companyId', 'date', 'email', 'score', 'userId']
var properties = getProperties(sheet);
// Get the next 100 rows as records
// [ ['test comment', 'ec24fmJeLA93l5jWPAN0', '1602547200.00', 'bdavis@wftst.com', '3', 'a8waViyRAJWGr2h6Gc3u'] ]
var records = getRecords(sheet);
// Export to Firestore private key removed for security reasons
var firestore = FirestoreApp.getFirestore('XXXXXX', 'XXXXXXX', 'XXXXXX');
exportToFirestore(firestore, sheetName, properties, records);
}
function exportToFirestore(firestore, collectionName, properties, records) {
records.map(function(record) {
// record: ['test comment', 'ec24fmJeLA93l5jWPAN0', '1602547200.00', 'bdavis@wftst.com', '3', 'a8waViyRAJWGr2h6Gc3u']
// props : [ 'comment', 'companyId', 'date', 'email', 'score', 'userId']
var data = {};
properties.forEach(function(prop,i) { data[prop] = record[i]; });
return data;
}).forEach(function(data) {
firestore.createDocument(collectionName, data);
});
}
function getProperties(sheet) {
return sheet.getRange(1, 1, 1, 6).getValues()[0]; // [ [ 'comment', 'companyId', 'date', 'email', 'score', 'userId'] ]
}
function getRecords(sheet) {
return sheet.getRange(2, 1, 1, 6).getValues();
}
question from:https://stackoverflow.com/questions/65649973/firestore-import-google-sheets-array