Skip to content

An education GitPod module intended to teach individuals how to use mongo on any machine.

License

Notifications You must be signed in to change notification settings

JavaScript-Open-Curriculum-Foundation/LearnMongoGitPod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoLearnPod

An education GitPod module intended to teach individuals how to use mongo on any machine. Here we are applying the idea of GhostPlate built on GitPod to education instead of Industry at scale ...

How to use?:

See that button? Click it with your right index finger and wait. If you use any other finger I will bite it off. Open in Gitpod

Then follow the directions inside the GitPod. Don't worry its still better than Microsoft documentation...

Unit Learning Objective

Students should be to:

  1. Use Docker Compose to start and stop mongoDB environment
  2. Use Docker, Terminal & MongoExpress to teach basic mongoDB concepts
  3. Distinguish between the name of a docker image (mongo) and the container name (learn-mongo)
  4. Use NPM Scripts to store docker commands

What did you build

Today we'll be learning how to use Docker Compose to learn MongoDB.

Unit Learning Objective

Students should be to:

  1. Use Docker Compose to start and stop mongoDB environment
  2. Use docker exec to access the mongoDB Shell
  3. Distinguish between the name of a docker image (mongo) and the container name (learn-mongo)
  4. Use NPM Scripts to store docker commands such as docker exec for mongo shell

About me

Hans McMurdy is an experianced web developer and coding teacher.

About

This is a brief mongo tutorial in GitPod and originally built for docker and docker compose which you can see here.

Using Mongo Shell to build a database

Type the following into a NEW terminal: mongo. Because no one in chat wanted to help me run it in headless mode (thanks, support :-) ).

Lets go ahead and create a new collection and use it.

Type the following into the terminal: use mongo.

We can then show the database we are using by using the db command.

Next we are going to insert some data into our new database. To do this we'll use the the insert command.

db.info.insert(
  {
    "country": "United States of America", 
    "state": "Arizona", 
    "cities": ["Phoenix", "Mesa", "Chandler"]
  }
)

This will insert a new document into the info collection.

Exercise Next, you should come up with 2 other states, with atleast two cities in each.

Finally, we will use the .find() method to find the document with a state of Arizona.

db.info.find({state:'Arizona'}).pretty()

Note that the .pretty() command just formates the data more properly.

By the end of the exercise your terminal should look something like following but with different examples:

If we open mongo-express, we should see a new database appeared. We can also use the terminal command show dbs to display them in terminal.

Using NPM Scripts

Package.json is used to demostrate NPM Scripts for use with docker

Students should be able to:

  • Identify the package.json file and the script section
  • Modify the package.json file to add the docker command
"mongo": "docker exec -it learn-mongo mongo",
  • Distinguish between the name of the docker image (mongo) and the container name (learn-mongo)

  • Demonstrate Mongo Terminal Commands

  1. Running with docker compose
    • docker exec -it learn-mongo mongo

Conclusion

Key learnings

Tips and advice

Final thoughts and next steps

About

An education GitPod module intended to teach individuals how to use mongo on any machine.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published