4.2 MongoDB Verification

MongoDB is the database used in our project. It is a modern and flexible database system that stores data in a format similar to JSON documents.

The reason for using MongoDB in our project is its flexibility and scalability. It allows us to store and retrieve data in a way that suits our project's needs. MongoDB's document-oriented structure makes it easy to work with data that varies in structure and doesn't require a fixed schema.

4.2.1 MongoDB Keys: Account Creation and Cluster Setup

Create a MongoDB account or Log in to MongoDB. Below are the given links for Sign up and Log In.

Signup: https://www.mongodb.com/cloud/atlas/register

Login: https://account.mongodb.com/account/login

  1. After logging in for the first time, kindly complete the Initial setup by adding details like ‘Not Sure’ as shown in the image below.

  1. Thereafter, click on the ‘Create’ button as shown below.

  1. After selecting the appropriate cluster tier to suit your requirements, provide a name for your cluster. After that, choose your preferred cloud provider and region based on your needs. Lastly, click on the ‘Create Deployment’ button located at the bottom of the page. You can initially choose the ‘Free Tier’ and upgrade your cluster tier later as per your need.

  1. Now proceed by clicking on the ‘Add user in database’ button. Following that, click on the ‘Choose connection method’ button to continue.

  1. After that, click on ‘Compass’.

  1. In the next step, copy the connection string and add it to your MONGODB_URL in the form field. (Please note that you remove ‘/’ from the end of the connection string)

  1. Click on network Access tab and then click on 'ADD IP ADDRESS' button as shown in below image.

  1. Then click on 'ALLOW ACCESS FROM ANYWHERE' button and then click on confirm.

  1. Click on App Services

  1. After that, select ‘React.JS + Realm Web Boilerplate’ option and click on the ‘Next’ button.

  1. The app is now created and you can copy the app ID shown in the image below and add it to MONGO_APP_ID in the form field.

  1. Now, click on the ‘Project Settings’ as shown in the image below.

  1. After that, copy the project ID as shown in the image below and add it to the MONGODB_PROJECT_ID in the form field.

  1. Click on the ‘Access Manager’ tab in the sidebar, select the API Keys tab, and then click on the ‘Create API Key’ button as shown in the image below.

  1. Now, add ‘Description’ for your API key (You can add anything in the description.). Following that, select all the ‘Project Permissions’ from the dropdown and click on the ‘Next’ button as shown in the image below.

  1. You get a public key and a private key as shown in the image below.

Add MONGODB_PROJECT_PUBLIC_API_KEY which you get from ‘MongoDb Project Public Key’. Add MONGODB_PROJECT_PRIVATE_API_KEY which you get from the ‘MongoDb Project Private Key

  1. Now, click on the ‘Done’ Button and then select the ‘App services’ tab as shown below.

  1. Now, select your created app.

  1. Click on ‘Linked Data Sources’ in the ‘Manage’ section and get the service name as shown below. Add this service name MONGODB_PROJECT_SERVICENAME in the form field.

4.2.3 GET MONGODB_APP_ID

You can get the MONGODB_APP_ID from the page URL where you visited the app services in the mongoDB atlas as shown in the image below.

4.2.4 SETUP REALM AUTH

  1. Login to your MongoDB account, go to ‘App services’, and select your app as shown in the image below.

  1. After that, go to Authentications, select Authentication Providers, and click on edit of email/Password as shown in the image.

  1. After that, set the settings as shown in the image below.

  1. For the password reset function, click on ‘New Function’.

// You Can Put this function in above-located place and make sure to change API URL

exports = async ( token, tokenId) => {

// do not confirm the user

const response = await context.http.post({

url: "APIURL/api/v2/sendForgotPasswordEmail",

body: {token: token},

encodeBodyAsJSON: true

})

}

  1. After that Name the function and paste the code which is provided above. In the above code, add your API URL of your env file and paste it as shown in the image below.

  1. Click on the ‘Save Draft’ button.

  1. Now, click on the ‘Review Draft & Deploy’ button as shown in the image.

  1. At last, click on the ‘Deploy’ button.

Last updated