Created
December 12, 2020 07:39
-
-
Save Rubix982/4db5f48a6ba133edb5781fd81b2306f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------------------- Question 1 ------------------------- */ | |
> use HOTEL | |
switched to db HOTEL | |
> dbs | |
2020-12-12T11:42:52.660+0500 E QUERY [thread1] ReferenceError: dbs is not defined : | |
@(shell):1:1 | |
> show dbs | |
admin 0.000GB | |
config 0.000GB | |
local 0.000GB | |
> db | |
HOTEL | |
> db.createCollection('HOTEL') | |
{ "ok" : 1 } | |
> db.HOTEL.insert({ | |
... "Address": { | |
... "Building": "123", | |
... "Street": "ABC-01", | |
... "Zipcode": "7500", | |
... }, | |
... "Town": "Karachi Down Town", | |
... "Cuisine": "Bakery", | |
... "Dishes": [ | |
... {"Pakistani": { "Price": "1K" }, "ratings": 9/10 }, | |
... {"Chinese": { "Price": "1.5K" }, "ratings": 8/10 }, | |
... {"British": { "Price": "1.6K" }, "ratings": 7/10 }, | |
... ], | |
... "Name": "New Down Town Hotel", | |
... "Hotel_ID": "PAK-30075" | |
... }) | |
WriteResult({ "nInserted" : 1 }) | |
> db.HOTEL.find({}) | |
{ "_id" : ObjectId("5fd467d4050cf88be9543838"), "Address" : { "Building" : "123", "Street" : "ABC-01", "Zipcode" : "7500" }, "Town" : "Karachi Down Town", "Cuisine" : "Bakery", "Dishes" : [ { "Pakistani" : { "Price" : "1K" }, "ratings" : 0.9 }, { "Chinese" : { "Price" : "1.5K" }, "ratings" : 0.8 }, { "British" : { "Price" : "1.6K" }, "ratings" : 0.7 } ], "Name" : "New Down Town Hotel", "Hotel_ID" : "PAK-30075" } | |
> db.HOTEL.insert({ | |
... "Address": { | |
... "Building": "234", | |
... "Street": "ABC-02", | |
... "Zipcode": "7501", | |
... }, | |
... "Town": "North Karachi Town", | |
... "Cuisine": "Bakery", | |
... "Dishes": [ | |
... {"Pakistani": { "Price": "0.7K" }, "ratings": 7/10 }, | |
... {"Chinese": { "Price": "1.1K" }, "ratings": 9/10 }, | |
... {"British": { "Price": "1.5K" }, "ratings": 8/10 }, | |
... ], | |
... "Name": "North Karachi Town Hotel", | |
... "Hotel_ID": "PAK-30076" | |
... }) | |
WriteResult({ "nInserted" : 1 }) | |
> db.HOTEL.insert({ | |
... "Address": { | |
... "Building": "345", | |
... "Street": "ABC-03", | |
... "Zipcode": "7502", | |
... }, | |
... "Town": "North Nazimabad Town", | |
... "Cuisine": "Bakery", | |
... "Dishes": [ | |
... {"Pakistani": { "Price": "1.0K" }, "ratings": 9.5/10 }, | |
... {"Chinese": { "Price": "1.1K" }, "ratings": 9/10 }, | |
... {"British": { "Price": "1.2K" }, "ratings": 8.5/10 }, | |
... ], | |
... "Name": "North Nazimabad Hotel", | |
... "Hotel_ID": "PAK-30077" | |
... }) | |
WriteResult({ "nInserted" : 1 }) | |
/* ------------------------- Question 2 ------------------------- */ | |
> db.HOTEL.find({}) | |
{ "_id" : ObjectId("5fd467d4050cf88be9543838"), "Address" : { "Building" : "123", "Street" : "ABC-01", "Zipcode" : "7500" }, "Town" : "Karachi Down Town", "Cuisine" : "Bakery", "Dishes" : [ { "Pakistani" : { "Price" : "1K" }, "ratings" : 0.9 }, { "Chinese" : { "Price" : "1.5K" }, "ratings" : 0.8 }, { "British" : { "Price" : "1.6K" }, "ratings" : 0.7 } ], "Name" : "New Down Town Hotel", "Hotel_ID" : "PAK-30075" } | |
{ "_id" : ObjectId("5fd46884050cf88be9543839"), "Address" : { "Building" : "234", "Street" : "ABC-02", "Zipcode" : "7501" }, "Town" : "North Karachi Town", "Cuisine" : "Bakery", "Dishes" : [ { "Pakistani" : { "Price" : "0.7K" }, "ratings" : 0.7 }, { "Chinese" : { "Price" : "1.1K" }, "ratings" : 0.9 }, { "British" : { "Price" : "1.5K" }, "ratings" : 0.8 } ], "Name" : "North Karachi Town Hotel", "Hotel_ID" : "PAK-30076" } | |
{ "_id" : ObjectId("5fd468c5050cf88be954383a"), "Address" : { "Building" : "345", "Street" : "ABC-03", "Zipcode" : "7502" }, "Town" : "North Nazimabad Town", "Cuisine" : "Bakery", "Dishes" : [ { "Pakistani" : { "Price" : "1.0K" }, "ratings" : 0.95 }, { "Chinese" : { "Price" : "1.1K" }, "ratings" : 0.9 }, { "British" : { "Price" : "1.2K" }, "ratings" : 0.85 } ], "Name" : "North Nazimabad Hotel", "Hotel_ID" : "PAK-30077" } | |
/* ------------------------- Question 3 ------------------------- */ | |
> db.HOTEL.find({}, { "_id": 0, "Town": 1, "Cuisine": 1, "Name": 1, "Hotel_ID": 1 }) | |
{ "Town" : "Karachi Down Town", "Cuisine" : "Bakery", "Name" : "New Down Town Hotel", "Hotel_ID" : "PAK-30075" } | |
{ "Town" : "North Karachi Town", "Cuisine" : "Bakery", "Name" : "North Karachi Town Hotel", "Hotel_ID" : "PAK-30076" } | |
{ "Town" : "North Nazimabad Town", "Cuisine" : "Bakery", "Name" : "North Nazimabad Hotel", "Hotel_ID" : "PAK-30077" } | |
/* ------------------------- Question 4 ------------------------- */ | |
> db.HOTEL.find( { "Hotel_ID": "PAK-30075" }, { "Hotel_ID": 0, "Name": 0 }) | |
{ "_id" : ObjectId("5fd467d4050cf88be9543838"), "Address" : { "Building" : "123", "Street" : "ABC-01", "Zipcode" : "7500" }, "Town" : "Karachi Down Town", "Cuisine" : "Bakery", "Dishes" : [ { "Pakistani" : { "Price" : "1K" }, "ratings" : 0.9 }, { "Chinese" : { "Price" : "1.5K" }, "ratings" : 0.8 }, { "British" : { "Price" : "1.6K" }, "ratings" : 0.7 } ] } | |
/* ------------------------- Question 5 ------------------------- */ | |
> db.HOTEL.find( { $or: [ { "Town": { $ne: "Karachi Down Town" } }, { "Dishes": { $exists: true, $in: ["Pakistani", "Chinese"] } } ] } ) | |
{ "_id" : ObjectId("5fd47302dc63de8e520aa6be"), "Address" : { "Building" : "345", "Street" : "ABC-03", "Zipcode" : "7502" }, "Town" : "North Nazimabad Town", "Cuisine" : "Bakery", "Dishes" : [ { "Pakistani" : { "Price" : "1.0K" }, "ratings" : 0.95 }, { "Chinese" : { "Price" : "1.1K" }, "ratings" : 0.9 }, { "British" : { "Price" : "1.2K" }, "ratings" : 0.85 } ], "Name" : "North Nazimabad Hotel", "Hotel_ID" : "PAK-30077" } | |
{ "_id" : ObjectId("5fd4730adc63de8e520aa6bf"), "Address" : { "Building" : "234", "Street" : "ABC-02", "Zipcode" : "7501" }, "Town" : "North Karachi Town", "Cuisine" : "Bakery", "Dishes" : [ { "Pakistani" : { "Price" : "0.7K" }, "ratings" : 0.7 }, { "Chinese" : { "Price" : "1.1K" }, "ratings" : 0.9 }, { "British" : { "Price" : "1.5K" }, "ratings" : 0.8 } ], "Name" : "North Karachi Town Hotel", "Hotel_ID" : "PAK-30076" } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment