Links

Send data to MongoDB

Tags: #googlesheets #mongodb #nosql #operations #automation
This notebook will help you send data from your spreadsheet to your MongoDB database collection
How To Use Template: Video

Input

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

Setup Google Sheet

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

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 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 from Google Sheets

df = gsheet.connect(spreadsheet_id).get(sheet_name=sheet_name)

Output

Send data to MongoDB

mongo.connect(host, port, user, passwd).send(df, collection_name, db_name, replace=True)