How to Create a Database Using the MongoDB Atlas User Interface

Over the past decade, the rise in popularity of cloud databases and database management systems has become very palpable. In fact, TechTarget anticipates cloud spending in 2024 to increase by up to 11%, with over 46% of respondents indicating that they would implement a “cloud-first” policy when deploying new apps. MongoDB has been one of the main drivers in the movement toward the cloud, especially after the company launched Atlas about six years ago.

MongoDB Atlas

Atlas is a database service offered by MongoDB that allows users to create and manage databases in the cloud. It provides a unique user interface for creating and managing databases, the ability to scale up or down depending on usage, and the power to deploy a new database with just a few clicks. Additionally, MongoDB Atlas provides robust security features such as authentication, encryption at rest, and role-based access control to keep your data safe.

Creating Your Database With Atlas

Now that we’ve familiarized ourselves with Atlas, we can now learn how to create a database in MongoDB. If you’re not well-versed in coding and programming languages, learning the basics will definitely be helpful, although it isn’t required. That said, make sure you have the latest version of JavaScript installed, as this guide will focus on teaching you how to connect to Atlas from your local Node.js or Express.js environment.

1. Creating a Cluster

From the MongoDB homepage, clicking on ‘create a free database’ will send you to the cluster creation wizard. Next, click ‘build a cluster’ and select a Cloud Provider (AWS, Google Cloud, Azure) and Region. You can also name your cluster, but keep in mind that you can only name it once and it cannot be edited. After you build a cluster, it will take about five to ten minutes for MongoDB to process and allow your cluster to be visible.

2. Obtain Access

Head to your computer’s network access or the ‘security’ tab and add the Database User and IP address of your current device. This will whitelist your IP address and allow entry from your local desktop. Switch to the ‘overview’ tab and click ’connect’, which will trigger a dialogue that will require you to connect your application and select the correct version of your driver. After doing both, you can now see your unique connection string.

3. Installing a Program Library

After you obtain access, you’ll then need to install Mongoose – Mongoose is a Java-oriented programming library that connects with Node. Upon installation, use the following code in db.js, replacing ‘dbname’ with your chosen database name, and ‘password’ with your user password:

//db.js

const mongoose = require('mongoose')

const url = `mongodb+srv://sample_user:<password>@my-sample-cluster-b3ugy.mongodb.net/<dbname>?retryWrites=true&w=majority`;

const connectionParams={

useNewUrlParser: true,

useCreateIndex: true,

useUnifiedTopology: true

}

mongoose.connect(url,connectionParams)

.then( () => {

console.log('Connected to database ')

})

.catch( (err) => {

console.error(`Error connecting to the database. \n${err}`);

})

4. Cluster and Document Management

A database can be composed of one or more collections, and MonoDB Atlas can allow for the use of up to 500 collections. From the ‘collections’ tab, you can view all the databases and collections that have been deployed. Using the Atlas UI, you can drop the database by either selecting or hovering on a database and then clicking on its trash can icon, then confirm the action by typing the name of the database and clicking ‘drop’.

Conclusion

For app developers and businesses alike, the use of MongoDB Atlas is very beneficial, as it’s an all-in-one platform that lets them create, deploy, and manage databases altogether. In the near future, expect to see Atlas adopted into various industries such as retail, manufacturing, finance, and many others. For more database management, programming, business tips, and others, check out the rest of our blog here at Technical Explore.

Sharing is Caring

About the Author

Team Technical Explore
(353 Articles Published)

Leave a Reply

Your email address will not be published. Required fields are marked *

Read More

crossmenu