- create a new database - name it company:
> use company
- Add all the employees listed below to the database company, in the collection employees:
> use company
# 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
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.
DB: ironhackers
|--> collection: developers {
{
name: "jack",
age: "34",
favoriteTeams: ["miami heat", "sacramento kings"],
ironhackers
.developers
.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
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
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] |