MongoDB

The database for you and me

Tuesday, Feb 4, 2020

MongoDB

Getting Started

Mac OS

brew install mongodb

Ubuntu

apt install mongodb

Connecting to a MongoDB Atlas Server

$ mongo "mongodb+srv://cluster0-h3iy9.mongodb.net/test" --username root

Mac OS

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

Ubuntu

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

The MongoDB Shell

Databases

{: .notice–info} Tip: If the database doesn’t yet exist, switching to it will implicitly create it.

{: .notice–warning} 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

Create

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.

Delete