MongoDB
Google Sheets + MongoDB
Query, Post and Sync Data from MongoDB
What is Sheet Director?
Sheet Director is a Google Workspace add-on that helps to manage and control bi-directional data flow between Google Sheets and several other applications like Google Calendar, Tasks, Contacts, Sheets, QuickBooks, FreshBooks, Zoho etc.Â
It is available in the Google Workspace Marketplace. Please check the Installation instructions to install the add-on.Â
What is MongoDB?
MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License which is deemed non-free by several distributions.
Setting up MongoDB with Sheet Director
Choose the MongoDb (Premuim app) from the list and choose the service which you want to perform
If you're opening it for the first time on the sheet, then you won't be having any connections.
Don't worry Sheet director provides a way to create a connection easily
To create the connection you have to provide the following details.
Connection name - Provide a nice name for the connection you're creating
Choosing the AuthType typically has two options Credentials and URL.
You can choose that based on your available credentialsIf you have chosen a URL then provide a valid MongoDB connection string.
Feel free to look into this article on how to get the connection string https://www.mongodb.com/docs/guides/atlas/connection-string/ÂIf you have chosen Credentials then you will have to provide the database name, username, password, protocol and finally the query string for the connection
Test Connection
Once you have provided the credentials you can easily check the connectivity by clicking on the test connection button
Based on the credentials authenticity, you will be having the feedbacks from the test
Once after connecting successfully, you can save the conection and continue.
These connections can be reused anytime and from any services used on the same Google Sheets
Querying on MongoDB
Once after saving the connection successfully, you can select the table and fields which you want to present on the Google Sheets
You also have a refresh button to get the updated tables list from the database
Filters
Filters can be used to query only the matching data from the tablesÂ
You can have multiple filters filters to a query
Sort
Sort can be used to sort the query results based on your interest.
You can have multiple sorts to a query
Max Result
You can limit how much no of records you want to fetch using a query
Destination Settings:
Configure the destination settings to save the records.
Scheduler Settings:
Switch on Run automatically to execute services automatically in the background.
Notification Settings:
Configure the Notification settings to set up the email templates and add attachments.
Click on execute to query the records in the Google Sheets.
Click save to save the service.
Sample Output
Let's try to query the Employees of a company
Without Filters and Sort
With Filters and Sort
Filter Applied in this sample output is to get Employees from City Bangalore and sort them in Ascending order by their First Name
Posting on MongoDB
Select the service to Post
Source Sheet
Choose the Source sheet where the data is located
Select the Status column
If status column is not there, simply click the + button to add the status header on your sheet(A status column will be created in Spreadsheet)
Select the Result column
If result column is not there, simply click the +button to add the result header on your sheet(A result column will be created in Spreadsheet)
Mapping
You can manually map the sheet data with the MongoDB fields
Click on execute to Post the records into the MongoDB.
Click save to save the service.
Click Execute to execute the service
After clicking on Execute you will be shown with the confirmation dialog of how many records will be posted, check that and click on "Post Now" to continue the posting
After successfully completeng the previous step you will be shown with the no successfully posted and failure records
You will also see that under the Result and the status column in the Google Sheet
Ouptut in MongoDB
Syncing on MongoDB
Select Sync as a service
Synchronize settings
Synchronization Key
The keys will be used for matching rows in Google Sheets with data in MongoDB, these keys will be your primary key. (this is identified automatically)
Conflict Resolution:
When Synchronization happens, there could be a conflict of data between Google Sheets and MongoDB.
MongoDB Wins
Google Sheet Wins
MongoDB Wins: Latest data from MongoDB will be updated into Google Sheets.
Google Sheet Wins: Latest data from Google Sheet will be updated into MongoDB.
Note: The major requirement in synchronization is the synchronize keys. If any of the keys is not having a value in the Google Sheet then Sheet Director will create it in the MongoDB
MongoDB Wins
Select MongoDB Wins.
The latest updated data from MongoDB will be updated in Google Sheets.
Updating a record, "Role" field with the value "Growth Engineering" in MongoDB, where the role was not updated in the Google Sheets
Lets execute this to get the updated record from MongoDB
The number of records that are ready to be synchronized will be shown.
It will also show all the data that are ready to be updated.
Click on Sync Now to sync all the data and update it into Google Sheets.
Click on the Refresh icon to refresh the data.
Before SynchronizingÂ
After Synchronizing
The value from MongoDB is now updated on Google Sheets
Google Sheet Wins
Select Google Sheet Wins.
The latest updated data from Google Sheets will be updated into MongoDB.
Let's execute this to Sync the updated record from Google Sheets
The number of records that are ready to be synchronized will be shown.
It will also show all the data that are ready to be updated.
Also, the number of data that needs to be updated into MongoDB will also be updated.
No of new records found in Sheet which are not present in MongoDB, that willl be created in MongoDB
Click on Sync Now to sync all the data and update it into Google Sheet.
Click on Refresh icon to refresh the data.
Sample
In this sample, we will update the values in all the "Roles" and add a new record to MongoDB from Google Sheets
Before Synchronizing
After Synchonizing