big data course homework 3

  1. import the file restaurants.json. #+begin_src sh :eval no :on-prev c38902-518a-4522-9db6-c4116d1f5a98 λ mongoimport --db hw3 --collection restaurants --file restaurants.json 2024-09-02T21:42:12.811+0300 connected to: mongodb:localhost/ 2024-09-02T21:42:12.952+0300 3772 document(s) imported successfully. 0 document(s) failed to import. #+end_src
  2. write a MongoDB query to display all the documents in the collection restaurants. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({})
BROKEN
  1. write a MongoDB query to display the fields restaurant_id, name, borough and cuisine for all the documents in the collection restaurants. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({}, {'restaurant_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1})
BROKEN
  1. write a MongoDB query to display the fields restaurant_id, name, borough and cuisine, but exclude the field _id for all the documents in the collection restaurants. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({}, {'restaurant_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1, '_id': 0})
BROKEN
  1. write a MongoDB query to display the fields restaurant_id, name, borough and zipcode, but exclude the field _id for all the documents in the collection restaurants. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({}, {'restaurant_id': 1, 'name': 1, 'borough': 1, 'zipcode': 1, '_id': 0})
BROKEN
  1. write a MongoDB query to display all the restaurants which are in the borough Bronx. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'borough': 'Bronx'})
BROKEN
  1. write a MongoDB query to display the first 5 restaurants which are in the borough Bronx. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'borough': 'Bronx'}).limit(5)
BROKEN
  1. write a MongoDB query to display the next 5 restaurants after skipping first 5 which are in the borough Bronx. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'borough': 'Bronx'}).skip(5).limit(1)
BROKEN
  1. write a MongoDB query to find the restaurants who achieved a score higher than 90. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'grades.score': {$gt: 90}})
BROKEN
  1. write a MongoDB query to find the restaurants that achieved a score higher than 80 but lower than 100. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'grades.score': {$gt: 80, $lt: 100}})
BROKEN
  1. write a MongoDB query to find the restaurants which have a latitude value less than 95.754168. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'address.coord.0': {$lt: 95.754168}})
BROKEN
  1. write a MongoDB query to find the restaurants that do not prepare any cuisine of 'American' and have a grade score is higher than 70 and latitude less than 65.754168. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({$and: [{$nor: [{'cuisine': {$regex: 'American'}}]}, {'grades.score': {$gt: 70}}, {'address.coord.0': {$lt: 65.754168}}]});
BROKEN
  1. write a MongoDB query to find the restaurants which do not prepare any cuisine of 'American' and have achieved a score higher than 70 and are have a longitude less than 65.754168. write this query without using the $and operator. same as previous one?
  2. write a MongoDB query to find the restaurants which do not prepare any cuisine of 'American ' and achieved a grade point 'A' and dont belong to the borough Brooklyn. the documents must be displayed according to the cuisine in descending order. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({$and: [{$nor: [{'cuisine': {$regex: 'American'}}, {'borough': 'Brooklyn'}]}, {'grades.grade': 'A'}]}).sort({'cuisine': -1});
BROKEN
  1. write a MongoDB query to find the restaurant id, name, borough and cuisine for restaurants which contain 'Wil' as first three letters for its name. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'name': {$regex: '^Wil.*'}}, {'_id': 1, 'name': 1, 'borough': 1});
BROKEN
  1. write a MongoDB query to find the restaurant id, name, borough and cuisine for restaurants which contain 'ces' as the last three letters in their names. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'name': {$regex: '.*ces$'}}, {'_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1});
BROKEN
  1. write a MongoDB query to find the restaurant's id, name, borough and cuisine for restaurants which contain 'Reg' somewhere in their names. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'name': {$regex: '.*Reg.*'}}, {'_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1});
BROKEN
  1. write a MongoDB query to find the restaurants which belong to the borough Bronx and that prepare either an American or a Chinese dish. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({$or: [{'cuisine': {$regex: '.*American.*'}, 'cuisine': {$regex: '.*Chinese.*'}}], 'borough': 'Bronx'});
BROKEN
  1. write a MongoDB query to find the restaurants id, name, borough and cuisine for the restaurants which belong to the borough Staten Island or Queens or Bronxor Brooklyn. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'borough': {$in: ['Queens', 'Staten Island', 'Bronxor Brooklyn']}}, {'_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1});
BROKEN
  1. write a MongoDB query to find the restaurant id, name, borough and cuisine for restaurants that dont belong to the borough Staten Island or Queens or Bronxor Brooklyn. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({$nor: [{'borough': {$in: ['Queens', 'Staten Island', 'Bronxor Brooklyn']}}]}, {'_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1});
BROKEN
  1. write a MongoDB query to find the restaurant id, name, borough and cuisine for restaurants that have achieved a score than isnt higher than 10. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'grades.score': {$lt: 10}}, {'_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1});
BROKEN
  1. write a MongoDB query to find the restaurants id, name, borough and cuisine for restaurants that prepare any dish except 'American' and 'Chinese', or if the restaurants name begins with the letters 'Wil'. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({$or: [{$nor: [{'cuisine': {$in: ['Chinese', 'American']}}]}, {'name': {$regex: '^Wil.*'}}]}, {'_id': 1, 'name': 1, 'borough': 1, 'cuisine': 1});
BROKEN
  1. write a MongoDB query to find the restaurant id, name, and grades for restaurants which have achieved a grade of "A" and scored 11 on an ISODate "2014-08-11T00:00:00Z". #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'grades.grade': 'A', 'grades.score': 11, 'grades.date': ISODate('2014-08-11T00:00:00Z')}, {'_id': 1, 'name': 1, 'grades': 1});
BROKEN
  1. write a MongoDB query to find the restaurant id, name and grades for those restaurants where the 2nd element of grades array contains a grade of "A" and score 9 on an ISODate "2014-08-11T00:00:00Z". #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'grades.1.grade': 'A', 'grades.1.score': 9, 'grades.1.date': ISODate('2014-08-11T00:00:00Z')}, {'_id': 1, 'name': 1, 'grades': 1});
BROKEN
  1. write a MongoDB query to find the restaurant id, name, address and geographical location for those restaurants where 2nd element of coord array contains a value which is more than 42 and up to 52.. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({$and: [{'address.coord.1': {$gt: 42}}, {'address.coord.1': {$lte: 52}}]}, {'_id': 1, 'name': 1, 'address': 1});
BROKEN
  1. write a MongoDB query to arrange the name of the restaurants in ascending order along with all the columns. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find().sort({'name': 1});
BROKEN
  1. write a MongoDB query to arrange the name of the restaurants in descending along with all the columns. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find().sort({'name': -1});
BROKEN
  1. write a MongoDB query to arrange the name of the cuisine in ascending order and for that same cuisine borough should be in descending order. i dont even know what that means but i guess this is what they wanted: #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find().sort({cuisine: 1, borough: -1})
BROKEN
  1. write a MongoDB query to know whether all the addresses contains the street or not. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'address.street': {$exists: false}}).count() == 0;
BROKEN
  1. write a MongoDB query which will select all documents in the restaurants collection where the coord field value is Double. see https://www.mongodb.com/docs/manual/reference/operator/query/type/ #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find({'address.coord.0': {$type: 1}, 'address.coord.1': {$type: 1}})
BROKEN
  1. write a MongoDB query which will select the restaurant id, name and grades of restaurants for which the operation of dividing the score by 7 returns 0 as a remainder. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find( {grades: {$elemMatch: {score: {$mod: [7, 0]}}}}, {'_id': 1, 'name': 1, 'grades': 1})
BROKEN
  1. write a MongoDB query to find the restaurant name, borough, longitude and lattitude and cuisine for those restaurants which contains 'mon' as three letters somewhere in its name. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find( {'name': {$regex: '.*mon.*'}}, {'_id': 0, 'name': 1, 'grades': 1, 'borough': 1, 'address.coord': 1, 'cuisine': 1})
BROKEN
  1. write a MongoDB query to find the restaurant name, borough, longitude and latitude and cuisine for those restaurants which contain 'Mad' as first three letters of its name. #+begin_src mongo :db hw3 :on-prev :eval no
    1. restaurants.find( {'name': {$regex: 'Mad.*'}}, {'_id': 0, 'name': 1, 'grades': 1, 'borough': 1, 'address.coord': 1, 'cuisine': 1})
BROKEN