Quickly get started with MongoDB Atlas

What is MongoDB Atlas?
MongoDB Atlas is a MongoDB cloud service provided by MongoDB Company. It is built and operated by the MongoDB database development team. It can be easily deployed, operated and expanded on AWS, Microsoft Azure and Google Cloud Platform. . MongoDB Atlas has built-in MongoDB security and operation and maintenance best practices, which can automatically complete infrastructure deployment, database construction, high-availability deployment, global distribution of data, backup and other operation and maintenance tasks that are time-consuming and require a lot of experience. Let you do this through a simple interface and API, so you can spend more valuable time building your applications.

Get started with MongoDB Atlas
To get started with MongoDB Atlas, you need to do the following:

  • Create a MongoDB Cloud account
  • Create a MongoDB Atlas cluster
  • Configure network access and create cluster users
  • Connect to the cluster

MongoDB Atlas offers a free version, so you don't need to provide any payment or credit card information.

Now, let's get started

Create a MongoDB Atlas account

Register
To create an Atlas account, please click to read the original article, or go to: https://www.mongodb.com/zh-cn/cloud/atlas/register?tck= china_wechat_article

You can sign up with a Google Account (recommended!); but you can also sign up with your own email address.

Organizations and Projects
Organizations and Projects
After registration, the system will guide you to create an organization and projects.

Organizational structures are used to group and define users and teams and grant them access to different projects.

Projects are used to define and organize Atlas resources, such as database clusters, triggers, and data lakes. When working with projects, you typically define the environment as the project. For example, you can create a separate project for development, testing, and production.

You can skip this step and go directly to the MongoDB Atlas management console. However, organizations and projects are required when creating a database cluster, so it is recommended that you perform this step now. If you decide to skip this step, you can create organizations and projects later.

Setting up a cluster in MongoDB Atlas
Once you have an Atlas account and create an organization and project, you can create a database cluster.

Make sure you select the desired organization and project in the top navigation dropdown. Then, select Clusters from the left navigation menu and click the Build Cluster button.

The Shared Cluster, Dedicated Cluster, and Multicloud and Multi-Geo Cluster options appear.

Shared clustering is the cheapest (or even free, depending on the use), but it uses shared hardware resources and networking.

Dedicated clusters provide a dedicated set of hardware and network isolation capabilities, as well as the option to automatically scale within a single region.

Multi-cloud and multi-geo clusters are built on the capabilities provided by dedicated clusters. This type of cluster can replicate data across multiple geographic regions for maximum availability. It also allows the creation of multi-cloud clusters using any combination of cloud service providers (AWS, Azure, and GCP).

If you want to try the free version, select "Shared Cluster".

Once you select your cluster type, you'll be able to choose from the three major cloud providers (Amazon Web Services, Microsoft Azure, and Google Cloud Platform) and select the region where your cluster will be hosted.

You can also select the cluster tier and other settings such as enabling backups and cluster name. Some options, such as MongoDB version cloud backup, are only available for paid clusters.

After selecting the required options, click the Create Cluster button. It may take a few minutes for Atlas to start and initialize your cluster in your selected cloud hosting provider.

When the cluster is ready, a green circle will appear next to the cluster name, indicating successful setup. Several indicators will also be displayed next to the cluster, including cluster connection status, operation options, and cluster size.

Next, let's connect to the newly created cluster.

Accessing a MongoDB Atlas cluster
To access a MongoDB Atlas cluster, you need to enable network access for your network or IP address and create a database user for connecting to the cluster. After that, you also need to generate a connection string for your application or script.

Allow access to your IP address
For security reasons, new DB clusters do not enable network access by default. You need to explicitly enable network access by whitelisting the addresses to connect to the cluster.

Entries in the whitelist can be IP addresses or subnets, or you can enable Allow access from any location. In general, we recommend that you do not grant access to all locations, but only to a specific subnet or list of IP addresses. This limits the connections the cluster accepts, making it more secure.

To enable network access to your cluster, click the Connect button in the cluster view of the Atlas Management Console. This will open the connection setup wizard.

To allow access from your current IP address, click the Add your current IP address button. If you need access from a different IP address or subnet, click the Add another IP address button and enter the IP or subnet using CIDR notation, such as 172.10.1.0/24.

Create a cluster user
If you need to connect to the database from a script or application, you must first create a MongoDB database user. Database users are used to connect to and use databases on Atlas. Note that this user is different from the user who logs into Atlas and manages clusters and resources there.

Database users are created per project and have access to all clusters in the project. You can also assign different roles and permissions to database users. Please note that the first user you create will automatically have administrative rights.

You can create database users just below Network Access Settings. Start by entering your username and password and then click the Create Database User button.

If you later need to add more users to the project, you can do so through the Security tab.

Generate database connection string
Depending on the application you are using, you may need to install the driver (library) for your platform to connect to a cluster in Atlas. You can view the full list of supported drivers here. For Compass (MongoDB UI application) or mongo shell application, the corresponding driver is already built-in.

Regardless of the application you use, you need to generate a database connection string for your cluster. If you happen to be in the process of creating a cluster, you can create the connection string as the last step in the process. After enabling network access and creating a database user, you can click on the "Select Connection Method" button, which will allow you to generate a connection string for your application. You can also create a connection string by clicking the Connect button on your cluster in Atlas' Clusters tab.

Click the Connect your app button and select a driver such as Node.js, Python, or other languages. Then, select the version to generate connection strings for your application. You can even generate code to test the connection by clicking the "Include full driver code example" option.

Note that the generated connection string does not include the actual cluster user login information. You need to replace and with your actual username and password. You also need to replace MyFirstDatabase with the actual database name in your cluster.

Sample Data
In the cluster view of the Atlas Management Console, click the ellipsis button […] and select Load Sample Data from the menu. Then confirm your choice.

This loads some sample collections that you can use to run test queries and learn more about MongoDB. You can view the loaded sample collection by clicking the Collection button on the cluster in Atlas' Clusters tab.

Conclusion
MongoDB Atlas is ideal if you lack the time or resources to manage all the infrastructure involved in a MongoDB cluster. You can create and run a cluster in minutes, allowing you to focus on application development instead of managing databases. With the free version of MongoDB Atlas, you can easily experience its various features.

Be sure to check out the Atlas documentation and MongoDB University courses for developers. These free courses detail how to work with MongoDB using Java, Javascript, Python, or C#/.Net.

Guess you like

Origin blog.csdn.net/MongoDBChina/article/details/134167673