- NoSQL
- Non-relational
- Uses embedded documents instead of joins
- Automatically creates db/collection if it doesn't exist already
- Follow the MongoDB link
- choose your OS
- Select the latest version
- Click 'Download'
- Follow the steps in the set up wizard
- make sure "Install MongoDB Compass" is checked
$ sudo apt install mongodb
Using the default host and port
- {host} => custom host
- {port} => custom port
$ mongo
Using a custom host and port
$ mongo {host}:{port}
Connect Remote:
- {username} => your mongoDB username
- {server} => your mongoDB cluster
$ mongo "mongodb+srv://{server}/{dbname}" --username {username}
Show all databases
> show dbs
select a database
- {database} => database you want to use
> use {database}
- {collection} => the collection you want to use
- to specify a criteria, use JSON notation
- {} => refers to all documents
> db.{collection}.find({}) # find all documents
> db.{collection}.find({"CS industry":"data science"}) # find all documents with the given criteria
> db.{collection}.insertOne({"game":"fortnite"}) # insert 1 element
> db.{collection}.insertMany([{"game":"fortnite"}, {"game":"angry birds"}]) # insert multiple elements (NEEDS TO BE AN ARRAY)
> db.{collection}.deleteOne({"language":"sql"}) # delete the first element with a matching criteria
> db.{collection}.deleteMany({"subject":"research"}) # delete all elements with a matching criteria
> db.{collection}.deleteMany({}) # clears all the documents in the db
# 1st argument: criteria
# 2nd argument: update to
# updateOne(<CRITERIA>, {$set:<NEW ENTRY>})
> db.{collection}.updateOne({"name":"omruti"}, {$set:{"loves":"fortnite"}}) # update one