Getting Started

Mac OS

brew install mongodb


apt install mongodb

Connecting to a MongoDB Atlas Server

$ mongo "mongodb+srv://" --username root

Mac OS

The config file is located at /usr/local/etc/mongod.conf


The config file is located at /etc/mogndob.conf

The MongoDB Shell


  • Show the name of the current database

  • Switch to the database example

    use example

Tip: If the database doesn’t yet exist, switching to it will implicitly create it.

  • List all available databases

    show dbs

Warning: If you switch to a new database and don’t add anything, the command above won’t show you the current database you are using since there isn’t anything inside of it.

Basic Operations in the Shell

There are 4 basic operations

  1. Create
  2. Read
  3. Update
  4. Delete


Use the insert function to add a document to a collection.

Documents can be represented in JavaScript Object Notation JSON and then inserted, which helps add simplicity.

  • Insert post object into the blog collection

    post = {
      "title": "Hello World",
      "content": "That's all folks.",
      "date": new Date()


  • Remove the document containing the username tommy from the users collection

      username: "tommy"