1

我想将数据从谷歌表发送到 mongodb 我在发送数据时遇到问题,主要是谷歌表中的数组字段。我是新手,提前谢谢。以下是我的代码

这是电子表格中的 code.gs 文件 我尝试过 Array(word)、[word]、String(word) 等等

function myFunction() {
  var sh1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Input");
  var rng = sh1.getDataRange().getValues();
  for(var i=1;i<3;i++){
    var sort =rng[i][9];
// basically sort is a string like "a, b, c, d, e, f" i have split the term based on ', '

    let word = sort.split(', '); 
   //word is an array which i want to import to my database
    var formData ={
    'Email':rng[i][1],
    'Timestamp':rng[i][0],
    'Attended':rng[i][2],
    'First Name':rng[i][3],
    'Phone Number':String(rng[i][4]),
    'Mob numbers':String(rng[i][5]),
    'Graduation Degree':rng[i][6],
    'Year of Study':rng[i][7],
    'College Name':rng[i][8],
    'Area of Interest':JSON.stringify(word),
    'referral code':rng[i][10],
    'Questions to the speaker':rng[i][11],
    'Current City':rng[i][12],
    'Interest Ratings':rng[i][13],
    'Filled form':rng[i][14],
    'Questions Asked':rng[i][15],                                   
  }
  Logger.log(formData);
    var params = {
   'method':'post',
  'payload':formData
  }
       var getId = UrlFetchApp.fetch('my url goes here',params); 
}
}

这是 webhook0 编辑器中的代码(POST REQUEST) (默认情况下,所有字段都是字符串,我在 Realm 中生成了一个模式,但这也不起作用)

exports = async function(payload) {
    const mongodb = context.services.get("mongodb-atlas");
    const eventsdb = mongodb.db("mydb");
    const eventscoll = eventsdb.collection("analysis");
    const result= await eventscoll.insertOne(payload.query);
    var id = result.insertedId.toString();
    if(result) {
        return JSON.stringify(id,false,false);  
     }
      return { text: `Error saving` };

从谷歌表输入数据谷歌表数据 数据以这种方式存储收集

4

0 回答 0