MongoDB-Queries 2
MongoDB-Queries 2
We’re going to continue practicing our queries and get a little more advanced. But the end of this
exercise you should be comfortable querying a mongoDB database.
Recommended studies:
Similar to the previous assignment you’ll want to look at the following commands and functions, they
will help you answer the queries below, you can (and will) also use commands from the previous
assignment.
Term Description
\ (escape character)
^
*
$or
$in
$nin
$not
ISODate()
$regex
$mod
$type
$options
$exists
1. Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those
restaurants which contain 'Wil' as first three letters for its name.
2. Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those
restaurants which contain 'ces' as last three letters for its name.
3. Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those
restaurants which contain 'Reg' as three letters somewhere in its name.
4. Write a MongoDB query to find the restaurants which belong to the borough Bronx and
prepared either American or Chinese dish.
5. Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those
restaurants which belong to the borough Staten Island or Queens or Bronxor Brooklyn.
6. Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those
restaurants which are not belonging to the borough Staten Island or Queens or Bronxor
Brooklyn.
7. Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those
restaurants which achieved a score which is not more than 10.
8. Write a MongoDB query to find the restaurant Id, name, borough and cuisine for those
restaurants which prepared dish except 'American' and 'Chinees' or restaurant's name begins
with letter 'Wil'
9. Write a MongoDB query to find the restaurant Id, name, and grades for those restaurants which
achieved a grade of "A" and scored 11 on an ISODate "2014-08-11T00:00:00Z" among many of
survey dates.
10. 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"
11. 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
upto 52.
12. Write a MongoDB query to arrange the name of the restaurants in ascending order along with
all the columns.
13. Write a MongoDB query to arrange the name of the restaurants in descending along with all the
columns.
14. Write a MongoDB query to arranged the name of the cuisine in ascending order and for that
same cuisine borough should be in descending order.
15. Write a MongoDB query to know whether all the addresses contains the street or not.
16. Write a MongoDB query which will select all documents in the restaurants collection where the
coord field value is Double.
17. Write a MongoDB query which will select the restaurant Id, name and grades for those
restaurants which returns 0 as a remainder after dividing the score by 7.
18. Write a MongoDB query to find the restaurant name, borough, longitude and attitude and
cuisine for those restaurants which contains 'mon' as three letters somewhere in its name.
19. 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.