From 388cca873c3288e53c606106e272a40cadfad543 Mon Sep 17 00:00:00 2001 From: Lu Date: Fri, 30 Jun 2023 18:55:26 +0200 Subject: [PATCH 1/5] employees done --- queries.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/queries.js b/queries.js index 99f09c5..79ae10e 100644 --- a/queries.js +++ b/queries.js @@ -4,4 +4,44 @@ print('Employees') // List all the employees. print('1. List all Employees') -db.employees.find({}).forEach(printjsononeline) \ No newline at end of file +db.employees.find({}).forEach(printjsononeline) + +//Find employee with whose name is Steve +db.employees.find( { "name": "Steve" } ) + +//Find all employees whose age is greater than 30. + +db.employees.find({ "age": {$gt: 30}}) + +//Find the employee whose extension is 2143. + +db.employees.find({"phone.ext": "2143" }) + +//Find all employees that are over 30. + +db.employees.find({ "age": {$: 30}}) + +//Find all employees that are less than or equal to 30. + +db.employees.find({ "age": {$lte: 30}}) + +//Find all the employees whose favorite food is pizza. + +db.employees.find({ "favorites.food": "pizza"}) + +//Change Willy’s personal phone number to "93-123-45-67". + +db.employees.updateOne({ "name": "Willy"}, { $set: { "phone.personal": "93-123-45-67"}}) + +//Change Bob’s privilege to normal user. + +db.employees.updateOne({ "name": "Bob"}, { $set: { "privileges": "user"}}) + + +//Find all employees whose favorite artist is equal to Picasso. + +db.employees.find( { "favorites.artist": "Picasso"}) + +//Delete the user John. + +db.employees.deleteOne( {"name": "John"}) \ No newline at end of file From 6ff4a9835190838530727dcc223c31320f82dfd4 Mon Sep 17 00:00:00 2001 From: Lu Date: Fri, 30 Jun 2023 19:48:31 +0200 Subject: [PATCH 2/5] restaurants done --- queries.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/queries.js b/queries.js index 79ae10e..736c691 100644 --- a/queries.js +++ b/queries.js @@ -44,4 +44,49 @@ db.employees.find( { "favorites.artist": "Picasso"}) //Delete the user John. -db.employees.deleteOne( {"name": "John"}) \ No newline at end of file +db.employees.deleteOne( { "name": "John" }) + +//List all the restaurants. + +db.restaurants.find() + +//Find all the restaurants and display only the fields restaurant_id, name, borough and cuisine. + +db.restaurants.find( {}, { _id: 1, name: 1, borough: 1, cuisine: 1 }) + + +//Find all the restaurants and display only the fields restaurant_id, name, borough and zip code. + +db.restaurants.find( {}, { _id: 1, name: 1, borough: 1, "adress.zipcode": 1 }) + +//Find the restaurants which are in the borough Bronx. + +db.restaurants.find( { "borough": "Bronx" }) + +////Find the restaurants which are in the borough Brooklyn with Steak cuisine. + +db.restaurants.find( { $and: [ { "borough": "Brooklyn" }, { "cuisine": "Steak" } ] } ) + +////Find the restauran ts which have achieved a score bigger than 90. + +db.restaurants.find( { $and: [ { "borough": "Brooklyn" }, { "cuisine": "Steak" } ] } ) + +////Find the restauran ts that do not prepare any Bakery cuisine and with a grade score equal or bigger than 70. + +db.restaurants.find( { $and: [ { "cuisine": { $ne: "Bakery" } }, { "grades.score": {$gt: 70} } ] } ) + +////Find the restauran ts which do not prepare any Chinese cuisine and have achieved a grade point A which do not belong to the borough Manhattan. + +db.restaurants.find( { $and: [ { "cuisine": { $ne: "Chinese" } }, { "grades.grade": "A" }, { "borough": { $ne: "Manhattan" } } ] } ) + +//Update restaurants with 'American ' cuisine to 'American' (without the space!!!) + +db.restaurants.updateMany({ "cuisine": "American "}, { $set: { "cuisine": "American"}}) + +//Update Morris Park Bake Shop address street to Calle falsa 123. + +db.restaurants.updateOne({ "name": "Morris Park Bake Shop"}, { $set: { "adress.street": "Calle falsa 123"}}) + +//Delete all the restaurants with address zipcode 10466. + +db.restaurants.deleteMany( { "address.zipcode": "10466" }) From 05390ee98f6bbf7fca6cac4d44daca3723f40d31 Mon Sep 17 00:00:00 2001 From: Lu Date: Sat, 1 Jul 2023 12:43:42 +0200 Subject: [PATCH 3/5] companies empezado --- queries.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/queries.js b/queries.js index 736c691..4202d59 100644 --- a/queries.js +++ b/queries.js @@ -90,3 +90,49 @@ db.restaurants.updateOne({ "name": "Morris Park Bake Shop"}, { $set: { "adress.s //Delete all the restaurants with address zipcode 10466. db.restaurants.deleteMany( { "address.zipcode": "10466" }) + +//Find all the companies that include 'Facebook' on the name field. + +db.companies.find( { "name": {$in: ["Facebook"]} }) + +//Find all the companies which category_code is 'web'. Retrive only their name field: + +db.companies.find( { "category_code": "web" }, { name: 1, _id: 0}) + +//Find all the companies named "Twitter", and retrieve only their name, category_code and founded_year fields. + + + +//Find all the companies who have web as their category_code, but limit the search to 50 companies. + + + +//Find all the companies which category_code is 'enterprise' and have been founded in 2005. Retrieve only the name, category_code and founded_year fields. + + + +//Find all the companies that have been founded on the 2000 or have 20 employees. Sort them descendingly by their number_of_employees. + + + +//Find all the companies that do not include web nor social on their category_code. Limit the search to 20 documents and retrieve only their name and category_code. + + + +//Find all the companies that were not founded on 'June'. Skip the first 50 results and retrieve only the founded_month and name fields. + + + +//Find all the companies that have 50 employees, but do not correspond to the 'web' category_code. + + + +//Find all the companies that have been founded on the 1st of the month, but does not have either 50 employees nor 'web' as their category_code. Retrieve only the founded_day and name and limit the search to 5 documents. + + + +//Find all the companies which the price_amount of the acquisition was 40.000.000. Sort them by name. + + + +//Find all the companies that have been acquired on January of 2014. Retrieve only the acquisition and name fields. From 1e4833a3f7f70b98717d7c97f6c797e493d67525 Mon Sep 17 00:00:00 2001 From: Lu Date: Sat, 1 Jul 2023 15:00:09 +0200 Subject: [PATCH 4/5] almost done --- queries.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/queries.js b/queries.js index 4202d59..306f162 100644 --- a/queries.js +++ b/queries.js @@ -101,38 +101,38 @@ db.companies.find( { "category_code": "web" }, { name: 1, _id: 0}) //Find all the companies named "Twitter", and retrieve only their name, category_code and founded_year fields. - +db.companies.find( { "name": "Twitter" }, { _id: 0, name: 1, category_code: 1, founded_year: 1}) //Find all the companies who have web as their category_code, but limit the search to 50 companies. - +db.companies.find( { "category_code": "web" }).limit(50) //Find all the companies which category_code is 'enterprise' and have been founded in 2005. Retrieve only the name, category_code and founded_year fields. - +db.companies.find( { $and: [ { "category_code": "enterprise" }, { "founded_year": 2005 }]}, { _id: 0, name: 1, category_code: 1, founded_year: 1}) //Find all the companies that have been founded on the 2000 or have 20 employees. Sort them descendingly by their number_of_employees. - +db.companies.find( { $or: [{ "number_of_employees": 20 }, { "founded_year": 2000 } ]}).sort({"number_of_employees": -1}) //Find all the companies that do not include web nor social on their category_code. Limit the search to 20 documents and retrieve only their name and category_code. - +db.companies.find( { $nor: [{ "category_code": "web" }, { "category_code": "social" }]}, { _id: 0, name: 1, category_code: 1}).limit(20) //Find all the companies that were not founded on 'June'. Skip the first 50 results and retrieve only the founded_month and name fields. - +db.companies.find( { "founded_month": { $ne: 6} }, { _id: 0, name: 1, founded_month: 1} ).skip(50) //Find all the companies that have 50 employees, but do not correspond to the 'web' category_code. - +db.companies.find( { $and: [ { "number_of_employees": 50 }, { "category_code": { $ne: "web"}}] } ) //Find all the companies that have been founded on the 1st of the month, but does not have either 50 employees nor 'web' as their category_code. Retrieve only the founded_day and name and limit the search to 5 documents. - +db.companies.find( { $and: [ { "founded_day": 1 }, { $nor: [ { "number_of_employees": 50 }, { "category_code": "web" } ] } ] }, { _id: 0, founded_day: 1, name: 1 } ).limit(5) //Find all the companies which the price_amount of the acquisition was 40.000.000. Sort them by name. - +db.companies.find( { } ) //Find all the companies that have been acquired on January of 2014. Retrieve only the acquisition and name fields. From 4e1824cd1f948617c9168eae72bfea1152911fe9 Mon Sep 17 00:00:00 2001 From: Lu Date: Sun, 9 Jul 2023 18:34:56 +0200 Subject: [PATCH 5/5] done --- queries.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/queries.js b/queries.js index 306f162..a33d862 100644 --- a/queries.js +++ b/queries.js @@ -133,6 +133,8 @@ db.companies.find( { $and: [ { "founded_day": 1 }, { $nor: [ { "number_of_employ //Find all the companies which the price_amount of the acquisition was 40.000.000. Sort them by name. -db.companies.find( { } ) +db.companies.find({"acquisition.price_amount": 40000000}).sort("name") //Find all the companies that have been acquired on January of 2014. Retrieve only the acquisition and name fields. + +db.companies.find({$and: [{"acquired_month": 1},{"acquired_year": 2014}]}, {_id: 0, acquisition: 1, name: 1}) \ No newline at end of file