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
- MongoDB Atlas account
- Vercel account - you need to be registered to be able to use the vercel CLI in the shell script we will run
- Node.js (v18+)
- Vercel CLI - this will be likely installed through the
deploy_vercel_function.sh
bash script
2. Setting up MongoDB Atlas
- Go to MongoDB Atlas and create a free shared cluster.
- Create a database called
yale3_profiles
(this is recommended but you can use your own db name do not forget to update this in yourconfig.json
file - Create a collection inside it called
profiles
(or your own choice of collection name but update the detail inconfig.json
) - 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. - Under Network Access, add IP address:
0.0.0.0/0
(allows all and only auth is connection string) - 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
atlas_int
branch
3.1 Clone the git clone -b atlas_int https://github.com/KartikayKaul/yale3.git
cd yale3-extension
config.json
3.2 Create the Create the config.json
file in extension root folder. This file is .gitignored
d 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
fromconfig.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
asMONGO_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.