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

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