Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Google Sheets Script to Remove Events from a MongoDB Database
* Delete the events from the Calendar and remover the eventID Reference from the sheet - wipeout.
function removeEventsFromMongoDB() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("Events");
var headerRows = 1; // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var numRows = range.getNumRows();
var data = range.getValues();
for (var i=headerRows; i<numRows; i++) {
// Cells are 1 indexed
var eventIdCell = range.getCell(i+1, columns.event_id+1);
// Make a POST request with form data.
var formData = {
'name': data[i][columns.desc],
'location': data[i][columns.loc],
'date_start': data[i][columns.date_start],
'date_end': data[i][columns.date_end],
'status': data[i][columns.status],
'owner': data[i][columns.owner],
'type': data[i][columns.type],
'event_id': data[i][columns.event_id]
var options = {
'method' : 'post',
'payload' : formData
var insertID = UrlFetchApp.fetch('', options);
eventIdCell.setValue(""); // Insert the new event ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.