You are on page 1of 2

In a database named MBA, create a collection called Revenue.

Go through the points below and


accordingly create some documents in this collection. The keys in the documents will be like
these: detail of outlets/ stores (id, name etc.), what product is being sold (type, name etc.),
quantity sold, city/ geography/ region, product items, selling amount, selling price, total sales,
age of the customer etc. Make sure you use arrays wherever applicable.

Instruction: Please go through the queries first and you would know how many documents to
create with what key value pairs.

Write queries in MongoDB which will answer the following:

1. How will you display all the documents in this collection?

2. How will you display only two fields apart from the id?

3. How will you display all the fields and not the id?

4. How will you display the sales which happened in the stores in Delhi.

5. Write a MongoDB query to display the first 5 sales happened in Delhi.

Hint: Find().limit(5)

6. How will you display the next 5 sales after skipping first 5 which happened in Delhi
Hint: Find().skip(5).limit(5)

7. How will you list all those sales agents who achieved a score more than 90.

8. How will you find the outlets which are located in Jaipur.

9. How will you identify the stores that do not sell merchandise and the user rating is more than
70.

10. Write a MongoDB query to find the store Id, name, and total sales for those stores which
contain ‘A' as first letter for the name of city.

11. How will you find the stores which contain ‘A’ as the last letter for the name of city.

Hint: Contains “two”: db.revenue.find({store_name:{$regex: 'two.*' ,"$options":"i"}}).limit(5)


Ends with “e”: db.sc.find({store_name: /e$/})

12. Write a MongoDB query to know whether all the addresses contain the pin code or not.

Hint: db.revenue.find({"pin code" : { $exists : true } } );

13. How will you write a query which will select those stores which returns 0 as a remainder
after dividing the score by 6.

You might also like