Skip to content

MongoDB Setup Guide

Shirley Cohen edited this page Mar 12, 2021 · 5 revisions

Follow this guide to set up your MongoDB environment for this class.

  1. Start up your Jupyter notebook instance and open a terminal window. Run the following commands in the terminal:
  2. wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
  3. sudo apt-get install gnupg
  4. wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
  5. echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
  6. sudo apt-get update
  7. sudo apt-get install -y mongodb-org

Note: #5 == a single command (i.e. /etc/apt/sources.list.d/mongodb-org-4.4.list is a parameter to tee).

Start up MongoDB (mongod service):
8. sudo systemctl start mongod
9. sudo systemctl status mongod
10. sudo systemctl enable mongod

Start using Mongo via the mongo shell:
11. mongo

Expected output:
(base) jupyter@notebook:~$ mongo
MongoDB shell version v4.4.4
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("94177966-f212-4294-85ff-78079836ddb7") }
MongoDB server version: 4.4.4
Welcome to the MongoDB shell.
For interactive help, type "help".

If you see any errors (instead of the output above), stop here and debug.

Run the following commands in the mongo shell:
12. db
13. use mydb
14. db.mycoll.insertOne({ x: 1, y: 2, z: "hi" })
15. show collections
16. db.mycoll.find()

Clone this wiki locally