This is a Google Apps Script project that allows you to import data from Google Sheets into MongoDB.
-
In your Google Sheets document, click on
Extensionsin the menu bar and then click onApps Script. -
Click on the
+button next toLibraryin the sidebar, paste the project ID1LeC5V6SEzbqWreUBIarpEYPHBVljtNI6WUaPxKAqOF618DuSM4Ty4c-3, click onSearchand then click onAdd. -
Create a new
SheetsToMongofile and paste the code below into the editor:// Function called by the button function submitData() { const field = SheetsToMongo.field; SheetsToMongo.createUpdateRequest({ lang: 'en', apiUrl: 'https://<url-of-the-stm-bridge>', collectName: 'stm_users_test', tableMap: (row, i) => row.some(Boolean) ? { _id: i + 3, email: field('string', row[0]), username: field('string', row[1]), firstName: field('string', row[2]), lastName: field('string', row[3]), birthData: field('date', row[4]), age: field('number', row[5]), role: field('string', row[6]), active: field('boolean', row[7]), comment: field('string', row[8], null), imageUrl: field('string', row[9]), } : null, displayTemplate: '{{username}} ({{role}})', }); } // Create a menu in the menu bar function addMenu() { const ui = SpreadsheetApp.getUi(); ui.createMenu('SheetsToMongo') .addItem('Submit', 'submitData') .addToUi(); } // Necessary for SheetsToMongo to work function sendCommand() { SheetsToMongo.sendCommand(arguments); }
-
(optional) Go to
Triggersin the sidebar and click onAdd Trigger. The select theaddMenufunction and click onSave. -
(optional) In your Google Sheets document, select the
A1cell, click onInsertin the menu bar and then click onDrawing. Add a rectangle shape withApplytitle, then click onSave and Close. Adjust the size of the rectangle to fit theA1cell. Right-click on the rectangle and click onAssign script. TypesubmitDataand click onOK. -
Copy the table from this example https://docs.google.com/spreadsheets/d/1u4HZnrn-koOQDTpGA9DYg4P1ID4FVw0SXO--b22xhQ8/edit?usp=sharing to your Google Sheets document.
-
You can now use
SheetsToMongo