Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
How to import Google Sheets Data to MongoDB Atlas Realm

I am trying to import the data I have from my Google sheets doc to MongoDB Atlas. I have written the app script as well as the function in the function editor. When I run my code in the function editor in MongoDB I get this ERROR "mongodb insert: argument must be an object". Here is what I have so far:

Google Sheet APP Script

function exportSheetsToMongo () {

  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName("US");
  var headersRows = 1;
  var range = sheet.getDataRange();
  var numsRows = range.getNumRows;
  var data = range.getValues(); 

  for (var i = headersRows; i < numsRows; i++) {
    var usZipIdCell = range.getCell( i +1, columns.zip+1) // Error possible here
    // var description = data[i][columns.description];
    
    var formData = {
      // 'country': data[i][columns.description],
      'zip': data[i][columns.zip],
      'city': data[i][columns.city],
      'state': data[i][columns.state],
      'state_code': data[i][columns.state_code],
      'county': data[i][columns.county],
      'county_code': data[i][columns.county_code],
      'lattitude': data[i][columns.lattitude],
      'longitude': data[i][columns.longitude],
      'accuracy': data[i][columns.accurcay]

    };
    var options = {
      'method':'post',
      'payload': formData
    };
    if(description) {
      var insertID  = UrlFetchApp.fetch("https://us-east-1.aws.data.mongodb-api.com/app/mmc-backend-mzbhi/endpoint", options);
      usZipIdCell.setValue(insertID)
    }
  } 
}

MongoDB Realm Function Editor

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

Partial Google Sheet Data

enter image description here

Data Base

enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!