DBMS EXAM 3 QUESTIONS AND
ANSWERS
Write a filter to return all documents where the listed property type is Chalet and the
chalet has at least 1 bedroom. - Correct Answers -{property_type: "Chalet", bedrooms:
{$gte: 1}}
Write a filter that returns all documents that are located in Turkey and where the host is
classified as a superhost. - Correct Answers -{"host.host_is_superhost": true,
"address.country": "Turkey"}
Write a filter to return all documents where the property type is Apartment and that have
exactly 5 amenities. - Correct Answers -{property_type: "Apartment", amenities: {$size:
5}}
Write a filter to return all documents that can accommodate exactly 2 people. - Correct
Answers -{accommodates: 2}
Write a filter to return all documents where the cancellation policy is "moderate" and the
price is less than $50. - Correct Answers -{cancellation_policy: "moderate", price: {$lt:
50}}
Write a filter to return all documents where the amenities contain "TV" and "Wifi". -
Correct Answers -{amenities: {$all: ["TV", "Wifi"]}}
Write a filter to return all documents where the number of bedrooms is not provided (null
or undefined). - Correct Answers -{"bedrooms": null}
Write a filter to return all documents where the host location is "Montreal, Quebec,
Canada" and the host has been verified via a "government_id" and a "phone". - Correct
Answers -{"host.host_location": "Montreal, Quebec, Canada",
"host.host_verifications": {$all: ["government_id", "phone"]}}
Write a filter to return all documents where the property type is Serviced apartment and
have a cleanliness review score > 9. - Correct Answers -{"property_type": "Serviced
apartment",
"review_scores.review_scores_cleanliness": {$gt: 9}}
Write a filter to return all documents where cancellation policy is "flexible" or
"super_strict_60" and picture urls for images are provided. - Correct Answers -
{cancellation_policy: {$in: ["flexible", "super_strict_60"]}, "images.picture_url": {$exists:
true, $ne: ""}}
, Write a filter to return all documents mentioning the word "clean" in the reviews and
having a review score cleanliness greater than 9. - Correct Answers -{reviews:
{$elemMatch: {comments: {$regex: 'clean'}}},
"review_scores.review_scores_cleanliness": {$gt: 9}}
Write a filter to return all documents with property type "Resort" that have all of the
following amenities: "Wifi", "Hot tub", "Wheelchair accessible". - Correct Answers -
{property_type: "Resort", amenities: {$all: ["Wifi", "Hot tub", "Wheelchair accessible"]}}
Write a filter to return all documents where the host name is "Ali", and the identity is
verified.(host_identity_verified) - Correct Answers -{"host.host_name": "Ali",
"host.host_identity_verified": true}
Write a filter to return all documents where the first amenity listed is "Wifi". - Correct
Answers -{"amenities.0": "Wifi"}
Write a filter to return all documents where one of the amenities begins with the letter
'H". - Correct Answers -{amenities: {$elemMatch: {$regex: "(?i)^H"}}}
Write a filter that returns all documents that have a market equal to: "Hong Kong", "New
York", "Porto", "Sydney" or "Istanbul" in the address field. - Correct Answers -
{"address.market": {$in: ["Hong Kong", "New York", "Porto", "Sydney", "Istanbul"]}}
Find all documents where genre is Drama - Correct Answers -{genres: "Drama"}
Find all movies where genre is Drama - Correct Answers -{genres: "Drama", type:
"movie"}
Find all movies where the genre is Drama or History - Correct Answers -{$or: [{genres:
"Drama}, {genres: "History"}]}
Find all movies where the genre is Drama and History - Correct Answers -{genres: {$all:
{"Drama", "History"]} type: "movie"}
Find movies with 2 genres - Correct Answers -{genres: {$size:2}}
Find all documents where the imdb.id is between 20000 and 40000 - Correct Answers -
{'imdb.id': {$gte: 20000, $lte: 40000}}
What is the hierarchy of MongoDB? - Correct Answers -Instace has databases has
collections has documents has fields and attributes
MongoDB doesn't have a (DDL / DML); why? - Correct Answers -DDL; each object has
its own structure, so no need for data definition language
ANSWERS
Write a filter to return all documents where the listed property type is Chalet and the
chalet has at least 1 bedroom. - Correct Answers -{property_type: "Chalet", bedrooms:
{$gte: 1}}
Write a filter that returns all documents that are located in Turkey and where the host is
classified as a superhost. - Correct Answers -{"host.host_is_superhost": true,
"address.country": "Turkey"}
Write a filter to return all documents where the property type is Apartment and that have
exactly 5 amenities. - Correct Answers -{property_type: "Apartment", amenities: {$size:
5}}
Write a filter to return all documents that can accommodate exactly 2 people. - Correct
Answers -{accommodates: 2}
Write a filter to return all documents where the cancellation policy is "moderate" and the
price is less than $50. - Correct Answers -{cancellation_policy: "moderate", price: {$lt:
50}}
Write a filter to return all documents where the amenities contain "TV" and "Wifi". -
Correct Answers -{amenities: {$all: ["TV", "Wifi"]}}
Write a filter to return all documents where the number of bedrooms is not provided (null
or undefined). - Correct Answers -{"bedrooms": null}
Write a filter to return all documents where the host location is "Montreal, Quebec,
Canada" and the host has been verified via a "government_id" and a "phone". - Correct
Answers -{"host.host_location": "Montreal, Quebec, Canada",
"host.host_verifications": {$all: ["government_id", "phone"]}}
Write a filter to return all documents where the property type is Serviced apartment and
have a cleanliness review score > 9. - Correct Answers -{"property_type": "Serviced
apartment",
"review_scores.review_scores_cleanliness": {$gt: 9}}
Write a filter to return all documents where cancellation policy is "flexible" or
"super_strict_60" and picture urls for images are provided. - Correct Answers -
{cancellation_policy: {$in: ["flexible", "super_strict_60"]}, "images.picture_url": {$exists:
true, $ne: ""}}
, Write a filter to return all documents mentioning the word "clean" in the reviews and
having a review score cleanliness greater than 9. - Correct Answers -{reviews:
{$elemMatch: {comments: {$regex: 'clean'}}},
"review_scores.review_scores_cleanliness": {$gt: 9}}
Write a filter to return all documents with property type "Resort" that have all of the
following amenities: "Wifi", "Hot tub", "Wheelchair accessible". - Correct Answers -
{property_type: "Resort", amenities: {$all: ["Wifi", "Hot tub", "Wheelchair accessible"]}}
Write a filter to return all documents where the host name is "Ali", and the identity is
verified.(host_identity_verified) - Correct Answers -{"host.host_name": "Ali",
"host.host_identity_verified": true}
Write a filter to return all documents where the first amenity listed is "Wifi". - Correct
Answers -{"amenities.0": "Wifi"}
Write a filter to return all documents where one of the amenities begins with the letter
'H". - Correct Answers -{amenities: {$elemMatch: {$regex: "(?i)^H"}}}
Write a filter that returns all documents that have a market equal to: "Hong Kong", "New
York", "Porto", "Sydney" or "Istanbul" in the address field. - Correct Answers -
{"address.market": {$in: ["Hong Kong", "New York", "Porto", "Sydney", "Istanbul"]}}
Find all documents where genre is Drama - Correct Answers -{genres: "Drama"}
Find all movies where genre is Drama - Correct Answers -{genres: "Drama", type:
"movie"}
Find all movies where the genre is Drama or History - Correct Answers -{$or: [{genres:
"Drama}, {genres: "History"}]}
Find all movies where the genre is Drama and History - Correct Answers -{genres: {$all:
{"Drama", "History"]} type: "movie"}
Find movies with 2 genres - Correct Answers -{genres: {$size:2}}
Find all documents where the imdb.id is between 20000 and 40000 - Correct Answers -
{'imdb.id': {$gte: 20000, $lte: 40000}}
What is the hierarchy of MongoDB? - Correct Answers -Instace has databases has
collections has documents has fields and attributes
MongoDB doesn't have a (DDL / DML); why? - Correct Answers -DDL; each object has
its own structure, so no need for data definition language