Skip to content

Instantly share code, notes, and snippets.

View sandrabosk's full-sized avatar
👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall

Aleksandra Bošković sandrabosk

👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall
  • Ironhack
View GitHub Profile
  1. create a new database - name it company:
> use company
  1. Add all the employees listed below to the database company, in the collection employees:
# create database
> use characters
# add first document in the collection enemies (collection gets created now)
> db.enemies.insertOne({
    "name": "Blinky",
    "color": "Red"
})
 
# check if Blinky is added
@sandrabosk
sandrabosk / mvc.md
Last active February 2, 2021 05:48

The MVC Pattern

  • Every time a request is made on the server, a Controller handles it.
  • This Controller will communicate with Models.
  • Models will read and write data directly to a database.
  • When the Controller has all information, it can pass that data to the View.
  • The View generates a Response which is a HTML page rendered to a client (in a browser).

Data modeling test

Let's practice modeling! Here you have some common problems. Please pair with another student and propose how to implement the schema for the following scenarios.

In this exercise, deciding what fields go into which collection is less important. Focus on deciding whether to use relations or embed documents.

Twitter

  • Users
  • One potential structure (needs to be built in the Compass and saved in the database):
DB: ironhackers 
|--> collection: developers {
                 
                 {
                    name: "jack",
                    age: "34",
                    favoriteTeams: ["miami heat", "sacramento kings"],

Compass Intro

  1. Create database named ironhackers.
  2. Create a collection named developers.
  3. Create documents with your and your 2 classmates information. Each document should have:
    • name (type String),
    • age (type Number),
    • favoriteTeams (type Array). It should be array of strings.
  • favoriteMovie (type Object) with movie title (type String) and array of mainActors (this should be array of strings),

[WIN] Install MongoDB - official docs

Run the following commands in your terminal:

$ wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
$ sudo apt update
$ sudo apt install mongodb --assume-yes
$ sudo apt remove mongo-tools mongodb mongodb-clients mongodb-server mongodb-server-core --assume-yes
$ sudo apt install mongodb-org --assume-yes

[LIN] Install MongoDB - official docs

Run the following commands in your terminal:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

# FOR VERSION 16.O4 ONLY
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

# FOR VERSION 18.O4 ONLY
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

[MAC]Install MongoDB - official docs

Run the following commands in your terminal:

$ brew tap mongodb/brew
$ brew install mongodb-community
$ brew services start mongodb-community

To start using MongoDB:

// ************************************************************************************
// https://www.codewars.com/kata/5539fecef69c483c5a000015/javascript
// Find all Backwards Read Primes between two positive given numbers (both inclusive),
// the second one always being greater than or equal to the first one.
//The resulting array or the resulting string will be ordered following the natural order
// of the prime numbers.
// Example
// backwardsPrime(2, 100) => [13, 17, 31, 37, 71, 73, 79, 97]