For Windows users
- Select the latest stable version (4.2.X+)
- Make sure the
- Download, and run the installation wizard, choose the default setup
- At the final step of the installer make sure "Install Mongo Compass" is checked
Try running the command
mongoin your terminal This probably won't work
mongocommand worked, congratulations! You're done!
- > Hang tight while we get everyone else sorted out
To set up the command line path open your file explorer, and right click on "This PC"
Select “Advanced System Settings”
Select “Environment Variables…” from the popup box
Under "System Variables", double click on Path
Paste the full file path to Mongo's
C:\Program Files\MongoDB\Server\4.2\binby default
Close then reopen your terminal.
mongoto start up your MongoDB environment
For Mac Users
- document database (NoSQL)
- horizontal sharding => can theoretically serve trillions of records
- built-in map-reduce for dynamic collections
- indexing on fields by value or free-text search
"Mongo is not a toy, although it can be fun to play with." - Josh Burke
to connect to a database you need a Mongo URI (or URL) identifying the server, port, etc.:
Connection URL format:
Note that the term "database" is overloaded: it refers to either:
- a single MongoDB process hosting many data sets
- a single MongoDB data set containing many related collections
a collection holds documents
this is analogous to a table in SQL
Like in a relational database, a document can be created, read, updated, deleted, indexed, searched for, ...
Unlike in a relational database, a document can contain any value for its fields, including arrays and nested objects.
Lab: Mongo CLI
Let's make our first Mongo collection through the terminal!
- Enter the Mongo shell
- Once you're in the mongo shell type
helpto see the options available to you
- Create an object and insert it into the collection
- Add a few
- View all the objects you just added
- View a single object
- Update an object
- Delete an object
_idis assigned by Mongo when a document is inserted
ObjectIdis a factory function that either generates a new id, or transforms a given string into a Mongo ID object
Lab: Exploring with Compass
When you installed MongoDB you should have also installed an application called "Compass." This is MongoDb's GUI tool. Let's open it up and see what it can do!
- Open compass and hit the green button that says "connect"
- Look for the database named "test" in the left side nav bar, and open it
- Create a new collection
- In the collection you just created try running through all the CRUD functions