-
Notifications
You must be signed in to change notification settings - Fork 3
MongoDB
Shirley Cohen edited this page Oct 19, 2023
·
15 revisions
Follow this procedure to set up your MongoDB environment for this class.
- Go to the GCP console and open MongoDB Atlas from the Partner Solutions section.
- On the MongoDB Atlas (Pay as You Go) page, click on the Subscribe button. _Note: If you get an error, that means that you don't have access to the billing account and your parter will need to do this step.
- Create an account on mongodb.com. Note: each partner needs to do this step.
- Once you have a registered for an your account, you should be redirected to Atlas or go to https://cloud.mongodb.com if you are not redirected automatically.
- On the Welcome to Atlas page, choose these options:
- What is your primary goal? Learn MongoDB.
- How long have you been developing software with MongoDB? New to MongoDB.
- What programming language are you primarily building on MongoDB with? Python.
- What kind(s) of data will your project use? Other.
- Will your application include any of the following architectural models? None.
- Click finish.
- From the Atlas overview page, click the create button to create a new deployment.
- Click Shared to create a free shared cluster and choose Google Cloud as the provider.
- Choose Iowa as the region and keep the other default values.
- Click Create Cluster. Wait for a few seconds for the cluster to get created.
- You will be prompted to create a database account. Choose a username and password for your account.
- Once your cluster has been created, you will see it show up in the Overview page.
- In the database deployment section of the Overview page, click on the Load Sample Data button. Wait about 5 minutes.
- Once all the sample data has been loaded, the database deployment will show the message "Sample dataset successfully loaded".
- Click the Browse Collections button and make sure you see 9 databases listed (from sample_airbnb to sample_weatherdata).
Please share the database account details with your project partner.
- Back in the GCP console, start up your JupyterLab environment.
- Open the Compute Engine page and find the external IP address assigned to your JupyterLab. Copy the address.
- Open Atlas and click on the Network Access link from the left-hand navigation.
- Click the Add IP address button.
- In the Access List Entry field, enter your IP address.
- In the Comment field, enter a descriptive name e.g. jupyterlab.
- Click the Confirm button.
- You should see the message "We are deploying your changes (current action: configuring MongoDB)" show up on the Network Access page.
Note: each time you restart your JupyterLab environment, a new external IP address will be assigned to the VM. This means that you will need to update your IP address in the Network Access page whenever you restart your work.
- Go to JupyterLab and open a terminal
- From the terminal, run these commands to install the MongoDB shell known as mongosh
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
mongosh --version
- Back in Atlas, from the left-hand navigation, click on Databases under the Deployments section.
- From the Databases page, click on the Connect button to connect to your cluster.
- Select Shell and copy the connection string. It should look similar to this:
mongosh "mongodb+srv://freesharedcluster.g22qkgv.mongodb.net/" --apiVersion 1 --username atlas
- Back in JupyterLab, paste the connection string for your cluster into a terminal window.
- You will be prompted to enter your password.
- The output should look similar to this:
(base) jupyter@jupyterlab:~$ mongosh "mongodb+srv://freesharedcluster.g22qkgv.mongodb.net/" --apiVersion 1 --username atlas
Enter password: ******
Current Mongosh Log ID: 652eed28c7a03d0843d8e3df
Connecting to: mongodb+srv://<credentials>@freesharedcluster.g22qkgv.mongodb.net/?appName=mongosh+2.0.2
Using MongoDB: 6.0.11 (API Version 1)
Using Mongosh: 2.0.2
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.
Atlas atlas-247t2h-shard-0 [primary] test>
Last, but not least, you should also add your partner to your Atlas instance, so that they can connect to the same MongoDB cluster with their mongodb.com account.
- From Atlas, click on the Access Manager drop-down list from the top of the page.
- Choose Project Access.
- Click on the Invite Users button.
- Add your partner's email address and click Invite to Organization.
Your setup is complete. Going forward you can bring up Atlas directly from https://cloud.mongodb.com without going through the GCP console.