Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FT_RMT_2408_ES David Carballo #2741

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 185 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ $ git commit -m "done"
$ git push origin master
```

- Create Pull Request so your TAs can check up your work.
- Create a Pull Request and submit your assignment.


## Deliverables

Expand Down Expand Up @@ -51,44 +52,199 @@ The database contains more than 18k documents. Each document holds the data abou

1. You will find the `.zip` file of the database on the **lab** folder.
2. Unzip the file
3. Navigate to this lab's folder in your terminal, and when inside, import the database to Mongo using the following command:
3. Open MongoDB Compass and connect to your MongoDB server.
4. Create a new database named `companiesDB` and inside of it a collection named `companies`.
5. Import the data from the .json file in to the collection `companies`.
6. Check on MongoDB Compass if everything goes ok:

**When running the `mongoimport` you should be located in the same folder as the `data.json` file.**
![image](https://user-images.githubusercontent.com/23629340/36534191-1f1bc5ec-17c6-11e8-9463-4945679b98c0.png)

```bash
$ mongoimport --db companiesDB --collection companies --file data.json
```
### Iteration 2

What this mongoimport will do for us is to create a database named _companiesDB_, and inside the database will create a collection named _companies_ which will be fed with _data.json_.
You already know how this goes, so let's start working:

_Side note_: In case errors or hanging with no response when running this command, add [--jsonArray](https://docs.mongodb.com/manual/reference/program/mongoimport/#cmdoption-mongoimport-jsonarray) at the end of the previous command.
1. All the companies whose name match 'Babelgum'. Retrieve only their `name` field.

4. Check on Mongo Compass if everything goes ok:
<details>
<summary>Solution</summary>

![image](https://user-images.githubusercontent.com/23629340/36534191-1f1bc5ec-17c6-11e8-9463-4945679b98c0.png)
- Query: `{name: 'Babelgum'}`
- Projection: `{name: 1, _id: 0}`

### Iteration 2
</details>

You already know how this goes, so let's start working:
<br>

1. All the companies whose name match 'Babelgum'. Retrieve only their `name` field.
2. All the companies that have more than 5000 employees. Limit the search to 20 companies and sort them by **number of employees**.

<details>
<summary>Solution</summary>

- Query: `{number_of_employees: { $gt: 5000 }}`
- Limit: `20`

</details>

<br>

3. All the companies founded between 2000 and 2005, both years included. Retrieve only the `name` and `founded_year` fields.
4. All the companies that had a IPO Valuation Amount of more than 100.000.000 and have been founded before 2010. Retrieve only the `name` and `ipo` fields.
5. All the companies that have less than 1000 employees and have been founded before 2005. Order them by the number of employees and limit the search to 10 companies.
6. All the companies that don't include the `partners` field.
7. All the companies that have a null type of value on the `category_code` field.
8. All the companies that have at least 100 employees but less than 1000. Retrieve only the `name` and `number of employees` fields.
9. Order all the companies by their IPO price in descending order.
10. Retrieve the ten companies with most employees, order by the `number of employees`
11. All the companies founded in the second semester of the year. Limit your search to 1000 companies.
12. All the companies founded before 2000 that have an acquisition amount of more than 10.000.000
13. All the companies that have been acquired after 2010, order by the acquisition amount, and retrieve only their `name` and `acquisition` field.
14. Order the companies by their `founded year`, retrieving only their `name` and `founded year`.
15. All the companies that have been founded on the first seven days of the month, including the seventh. Sort them by their `acquisition price` in descending order. Limit the search to 10 documents.
16. All the companies on the 'web' `category` that have more than 4000 employees. Sort them by the number of employees in ascending order.
17. All the companies whose acquisition amount is more than 10.000.000 and the currency is 'EUR'.
18. All the companies that have been acquired in the first trimester of the year. Limit the search to 10 companies, and retrieve only their `name` and `acquisition` fields.
19. All the companies that have been founded between 2000 and 2010, but have not been acquired before 2011.

<details>
<summary>Solution</summary>

- Query: `{$and: [{founded_year: {$gte: 2000}}, {founded_year:{$lte: 2005}}]}`
- Projection: `{name: 1, _id: 0, founded_year: 1}`

</details>

<br>

4. All the companies that had a IPO Valuation Amount of more than 100,000,000 and have been founded before 2010. Retrieve only the `name` and `ipo` fields.

<details>
<summary>Solution</summary>

- Query: `{$and: [{'ipo.valuation_amount': {$gte: 10000000}}, {founded_year:{$lt: 2010}}]}`
- Shorthand: `{founded_year: {$lt:2010}, "ipo.valuation_amount": {$gt: 100000000}}`
- Projection: `{name: 1, _id: 0, ipo: 1}`

</details>

<br>

5. All the companies that don't include the `partners` field.

<details>
<summary>Solution</summary>

- Query: `{partners: {$exists: false}}`

</details>

<br>

6. All the companies that have a null type of value on the `category_code` field.

<details>
<summary>Solution</summary>

- Query: `{category_code: {$type: 'null'}}`

</details>

<br>

7. Order all the companies by their IPO price in descending order.

<details>
<summary>Solution</summary>

- Sort: `{'ipo.valuation_amount': -1}`

</details>

<br>

8. Retrieve the 10 companies with the most employees, order by the `number of employees`.

<details>
<summary>Solution</summary>

- Query: `{ number_of_employees: { $exists: true } }`
- Sort: `{number_of_employees: -1}`
- Limit: `10`

</details>

<br>

9. All the companies founded in the second semester of the year (July to December). Limit your search to 1000 companies.

<details>
<summary>Solution</summary>

- Query: `{founded_month: {$gte: 7}}`
- Limit: `1000`

</details>

<br>

10. All the companies that have been founded on the first seven days of the month, including the seventh. Sort them by their `acquisition price` in descending order. Limit the search to 10 documents.

<details>
<summary>Solution</summary>

- Query: `{founded_day: {$lte: 7}}`
- Sort: `{'acquisition.price_amount': -1}`
- Limit: `10`

</details>

<br>

### Iteration 3 (Bonus)

For an extra challenge and additional practice, try the following queries:

1. All the companies that have been acquired after 2010, order by the acquisition amount, and retrieve only their `name` and `acquisition` field.

<details>
<summary>Solution</summary>

- Query: `{'acquisition.acquired_year': {$gt: 2010}}`
- Projection: `{name: 1, acquisition: 1, _id: 0}`
- Sort: `{'acquisition.price_amount': -1}`

</details>

<br>

2. Order the companies by their `founded year`, retrieving only their `name` and `founded year`.

<details>
<summary>Solution</summary>

- Query: `{'founded_year': { '$ne': null }}`
- Projection: `{name: 1, founded_year: 1, _id: 0}`
- Sort: `{founded_year: 1}`

</details>

<br>

3. All the companies on the 'web' `category` that have more than 4000 employees. Sort them by the number of employees in ascending order.

<details>
<summary>Solution</summary>

- Query: `{$and: [{category_code: 'web'}, {number_of_employees: {$gt: 4000}}]}`
- Sort: `{number_of_employees: 1}`

</details>

<br>

4. All the companies whose acquisition amount is more than 10,000,000 and the currency is 'EUR'.

<details>
<summary>Solution</summary>

- Query: `{$and: [{'acquisition.price_currency_code': 'EUR'}, {'acquisition.price_amount': {$gt: 10000000}}]}`

</details>

<br>

5. All the companies that have been founded between 2000 and 2010, but have not been acquired before 2011.

<details>
<summary>Solution</summary>

- Query: `{$and: [{founded_year: {$gte: 2000}}, {founded_year: {$lte: 2010}}, {'acquisition.acquired_year':{$gt:2011}}]}`

</details>

<br>

Happy Coding! :heart:
Binary file added crunchbase-dataset/__MACOSX/._data.json
Binary file not shown.
Loading