Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I got an Appscript created for Google sheets to pull my Firestore database into Google Sheets on command. However, its pulling data with "StringValue" included in the data as well. How do I remove this? (see screenshots) enter image description here

function onOpen() {
 SpreadsheetApp.getUi().createMenu('?? Firestore').addItem('Import DB', 'importFromFirestore').addToUi();
}


// took my key out for obvious reasons. Replaced with XXXXXXXX - I know its right b/c it pulls the right data
function getFirestore() {
 return FirestoreApp.getFirestore('XXXXXX', 'XXXXXXX', 'XXXXXXXX'); 
  }

function importFromFirestore() {
  // 1. Get a Firestore insance
  const firestore = getFirestore(); 
  
  // 2. Get a collection from Firestore
  const allDocuments = firestore.getDocuments('scores').map(function(document) {
    return document.fields;
  });
  
  // 3. Get the first document from the collection
  const first = allDocuments[0];
  const columns = Object.keys(first);
  
  const sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow(columns);
  
  // 4. Turn each document into an array to be appended to the sheet
  allDocuments.forEach(function(document) {
    const row = columns.map(function(column) {
      return document[column];
    });
    sheet.appendRow(row);
  });
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
256 views
Welcome To Ask or Share your Answers For Others

1 Answer

In your code change:

Before

// 2. Get a collection from Firestore
const allDocuments = firestore.getDocuments('scores').map(function(document) {
return document.fields;
});

After

// 2. Get a collection from Firestore
const allDocuments = firestore.getDocuments('scores').map(function(document) {
return document.obj;
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...