Skip to content

Latest commit

 

History

History
71 lines (46 loc) · 2.41 KB

MongoDB_Send_data_to_Google_Sheets.md

File metadata and controls

71 lines (46 loc) · 2.41 KB



Template request | Bug report | Generate Data Product

Tags: #mongodb #googlesheets #nosql #operations #automation

Author: Oketunji Oludolapo

This notebook will help you send data from your MongoDB database collection to your spreadsheet

How To Use Template: Video

Input

from naas_drivers import mongo, gsheet
import pandas as pd
import naas

Setup MongoDB

  • Get your user, password and connection URL details from your MongoDB Atlas Cluster How To get Required MongoDB details: Article
user = "your user"
passwd = "your password"
host = "Your Connection URL"
port = 9090
collection_name = "COLLECTION NAME"
db_name = "DATABASE NAME"

Setup Google Sheet

spreadsheet_id = "------"
sheet_name = "Sheet1"

Setup Naas

naas.scheduler.add(
    cron="0 9 * * *"
)  # Send in production this notebook and run it, every day at 9:00.

# use this to delete your automation
# naas.scheduler.delete()

Model

Get data in MongoDB

df = mongo.connect(host, port, user, passwd).get(collection_name, db_name)

Output

Send data to Google Sheet

gsheet.connect(spreadsheet_id).send(sheet_name=sheet_name, data=df, append=False)