|
| 1 | +# MongoDB Queries Practice |
| 2 | + |
| 3 | +Write a MongoDB query to: |
| 4 | + |
| 5 | +1. Display all the documents in the restaurants collection. |
| 6 | +``` |
| 7 | +Paste your solution here |
| 8 | +``` |
| 9 | + |
| 10 | +2. Display the fields restaurant_id, name, borough and cuisine for all the documents in the collection. |
| 11 | +``` |
| 12 | +Paste your solution here |
| 13 | +``` |
| 14 | + |
| 15 | +3. Display the fields restaurant_id, name, borough and cuisine, but exclude the field _id for all the documents in the collection. |
| 16 | +``` |
| 17 | +Paste your solution here |
| 18 | +``` |
| 19 | + |
| 20 | +4. Display the fields restaurant_id, name, borough and zip code, but exclude the field _id for all the documents in the collection. |
| 21 | +``` |
| 22 | +Paste your solution here |
| 23 | +``` |
| 24 | + |
| 25 | +5. Display all the restaurants which are in the borough Bronx. |
| 26 | +``` |
| 27 | +Paste your solution here |
| 28 | +``` |
| 29 | + |
| 30 | +6. Display the first 5 restaurants which are in the borough Bronx. |
| 31 | +``` |
| 32 | +Paste your solution here |
| 33 | +``` |
| 34 | + |
| 35 | +7. Display the next 5 restaurants after skipping first 5 which are in the borough Bronx. |
| 36 | +``` |
| 37 | +Paste your solution here |
| 38 | +``` |
| 39 | + |
| 40 | +8. Find the restaurants who achieved a score more than 90. |
| 41 | +``` |
| 42 | +Paste your solution here |
| 43 | +``` |
| 44 | + |
| 45 | +9. Find the restaurants that achieved a score, more than 80 but less than 100. |
| 46 | +``` |
| 47 | +Paste your solution here |
| 48 | +``` |
| 49 | + |
| 50 | +10. Find the restaurants which are located in latitude value less than -95.754168. |
| 51 | +``` |
| 52 | +Paste your solution here |
| 53 | +``` |
| 54 | + |
| 55 | +11. Find the restaurants that do not prepare any cuisine of 'American' and their grade score is more than 70 and latitude less than -65.754168. |
| 56 | +``` |
| 57 | +Paste your solution here |
| 58 | +``` |
| 59 | + |
| 60 | +12. Find the restaurants which do not prepare any cuisine of 'American' and achieved a score more than 70 and are located in the longitude less than -65.754168. |
| 61 | + |
| 62 | +Note : Do this query without using $and operator. |
| 63 | +``` |
| 64 | +Paste your solution here |
| 65 | +``` |
| 66 | + |
| 67 | +13. Find the restaurants which do not prepare any cuisine of 'American' and achieved a grade point 'A' and does not belong to the borough Brooklyn. The document must be displayed according to the cuisine in descending order. |
| 68 | +``` |
| 69 | +Paste your solution here |
| 70 | +``` |
| 71 | + |
| 72 | +14. Find the restaurant_id, name, borough and cuisine for those restaurants which contain 'Wil' as first three letters in its name. |
| 73 | +``` |
| 74 | +Paste your solution here |
| 75 | +``` |
| 76 | + |
| 77 | +15. Find the restaurant_id, name, borough and cuisine for those restaurants which contain 'ces' as last three letters in its name. |
| 78 | +``` |
| 79 | +Paste your solution here |
| 80 | +``` |
| 81 | + |
| 82 | +16. Find the restaurant_id, name, borough and cuisine for those restaurants which contain 'Reg' as three letters somewhere in its name. |
| 83 | +``` |
| 84 | +Paste your solution here |
| 85 | +``` |
| 86 | + |
| 87 | +17. Find the restaurants which belong to the borough Bronx and prepare either American or Chinese cuisine. |
| 88 | +``` |
| 89 | +Paste your solution here |
| 90 | +``` |
| 91 | + |
| 92 | +18. Find the restaurant_id, name, borough and cuisine for those restaurants which belong to the boroughs Staten Island or Queens or Bronx or Brooklyn. |
| 93 | +``` |
| 94 | +Paste your solution here |
| 95 | +``` |
| 96 | + |
| 97 | +19. Find the restaurant_id, name, borough and cuisine for those restaurants which don't belong to the boroughs Staten Island or Queens or Bronx or Brooklyn. |
| 98 | +``` |
| 99 | +Paste your solution here |
| 100 | +``` |
| 101 | + |
| 102 | +20. Find the restaurant_id, name, borough and cuisine for those restaurants which achieved a score that is not more than 10. |
| 103 | +``` |
| 104 | +Paste your solution here |
| 105 | +``` |
| 106 | + |
| 107 | +21. Find the restaurant_id, name, borough and cuisine for those restaurants which either prepare dishes except 'American' and 'Chinese' or has a name which begins with the letters 'Wil'. |
| 108 | +``` |
| 109 | +Paste your solution here |
| 110 | +``` |
| 111 | + |
| 112 | +22. Find the restaurant_id, name, and grades for those restaurants which achieved an A grade and scored 11 on the date "2014-08-11T00:00:00Z" among many of survey dates. |
| 113 | +``` |
| 114 | +Paste your solution here |
| 115 | +``` |
| 116 | + |
| 117 | +23. 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". |
| 118 | +``` |
| 119 | +Paste your solution here |
| 120 | +``` |
| 121 | + |
| 122 | +24. 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 upto 52. |
| 123 | +``` |
| 124 | +Paste your solution here |
| 125 | +``` |
| 126 | + |
| 127 | +25. Arrange the name of the restaurants in ascending order along with all the columns. |
| 128 | +``` |
| 129 | +Paste your solution here |
| 130 | +``` |
| 131 | + |
| 132 | +26. Arrange the name of the restaurants in descending along with all the columns. |
| 133 | +``` |
| 134 | +Paste your solution here |
| 135 | +``` |
| 136 | + |
| 137 | +27. Arrange the restaurants in ascending order of cuisines and descending order of boroughs. |
| 138 | +``` |
| 139 | +Paste your solution here |
| 140 | +``` |
| 141 | + |
| 142 | +28. Check whether all the resturant addresses contain the street or not. |
| 143 | +``` |
| 144 | +Paste your solution here |
| 145 | +``` |
| 146 | + |
| 147 | +29. Display all documents in the restaurants collection where the coord field value is a Double. |
| 148 | +``` |
| 149 | +Paste your solution here |
| 150 | +``` |
| 151 | + |
| 152 | +30. Display the restaurant_id, name and grades for those restaurants which have a grade divisible by 7. |
| 153 | +``` |
| 154 | +Paste your solution here |
| 155 | +``` |
| 156 | + |
| 157 | +31. Find the restaurant name, borough, longitude and latitude and cuisine for those restaurants which contain 'mon' as three letters somewhere in its name. |
| 158 | +``` |
| 159 | +Paste your solution here |
| 160 | +``` |
0 commit comments