MongoDB Atlas Integration Guide - KartikayKaul/Yale3 GitHub Wiki

Overview

This guide will walk you through enabling cloud saving of linkedin profile data to MongoDB Atlas, using Vercel serverless function that securely writes to your database via HTTPS.

1. Prerequisites

2. Setting up MongoDB Atlas

  1. Go to MongoDB Atlas and create a free shared cluster.
  2. Create a database called yale3_profiles (this is recommended but you can use your own db name do not forget to update this in your config.json file
  3. Create a collection inside it called profiles (or your own choice of collection name but update the detail in config.json)
  4. Under Database Access, create a user and give them read and write access. Remember the password you have created. You need to manually put that in your connection string that you will copy to your config.json file.
  5. Under Network Access, add IP address: 0.0.0.0/0 (allows all and only auth is connection string)
  6. Find and Copy the connection string eg:
mongodb+srv://yaleuser:[email protected]/yale3?retryWrites=true&w=majority&appName=Cluster0

Append this to your config.json:-

{
    ...
    "MONGODB_URI": "mongodb+srv://yaleuser:[email protected]/yale3?retryWrites=true&w=majority&appName=Cluster0",
    ...
}

3. Deploy Vercel Serverless Function

3.1 Clone the atlas_int branch

git clone -b atlas_int https://github.com/KartikayKaul/yale3.git
cd yale3-extension

3.2 Create the config.json

Create the config.json file in extension root folder. This file is .gitignoredd to prevent leaking the secrets to GitHub. Do NOT commit this. config.dummy.json file has been provided to show what are the recommended attribute values in this file. The only thing that is unique to you is your MONGODB_URI which you retrieved from the mongoDB atlas website.

3.3 Run the deployment script

Run this from the root of your project. This is where the deploy_vercel_function.sh is located.

bash deploy_vercel_function.sh`

The Script:-

  • reads the MONGODB_URI from config.json
  • creates a Vercel serverless function at api/save.js using the MongoDB Node.js driver
  • deploys the function using Vercel CLI
  • Captures and stores the final public HTTPS endpoint into config.json as MONGO_API_ENDPOINT

4. Test / Verify

  • You can use console.log to check status
  • I usually monistor via Atlas webUI to see if new documents are coming in
  • It is recommended that you can restrict the MongoDB IP Access to known Vercel IPs if you want. You are allowed to do that but ensure you are using correct vercel ip range.

5. Good to Go

This feature is currently under testing and not under main branch of repo which means it is not a stable feature yet.