Mongo

The database for you and me

Monday, Apr 13, 2020

MongoDB

Getting Started

Installing MongoDB

Configuring MongoDB

MongoDB config files are written in YAML, an example mongodb.conf file is provided below

Connecting to a MongoDB Atlas Server

# Using a single URI
mongo mongodb+srv://tommy:fighton@cluster-name.mongodb.net/dbname

# Using a URI and two flags
# Short Form
mongo 'mongodb+srv://cluster-name.mongodb.net/dbname' -u 'tommy' -p 'fighton'
# Long Form
mongo 'mongodb+srv://cluster-name.mongodb.net/dbname' --username 'tommy' --password 'fighton'

The MongoDB Shell

Databases

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

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