MAPREDUCE Elite
From NoSQLZoo
#ENCODING
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-16')
#MONGO
from pymongo import MongoClient
client = MongoClient()
client.progzoo.authenticate('scott','tiger')
db = client['progzoo']
#PRETTY
import pprint
pp = pprint.PrettyPrinter(indent=4)
Introducing the elite database **WORK IN PROGRESS
These questions will introduce the "elite" database, which contains data about the video game Elite Dangerous
There are two collections, commodities and systems. Inside systems there is are nested documents called stations
A system has many stations, and a station imports,exports, and bans many commodities
Though it could, commodities does not make use of nested documents and the average document looks something like this.
{
"_id" : ObjectId("55af74e7402aa43f1ce7e3a3"),
"name" : "Explosives",
"average_price" : 267,
"category" : "Chemicals"
}
systems look like this. For readability this example only has one station.
{
"_id" : ObjectId("55afa14a369fd51c351f1cb8"),
"stations" : [
{
"max_landing_pad_size" : "L",
"has_blackmarket" : 0,
"has_commodities" : 0,
"updated_at" : 1430931780,
"id" : 5611,
"has_outfitting" : 1,
"government" : "Patronage",
"state" : "None",
"system_id" : 1,
"has_shipyard" : 1,
"type" : "Unknown Starport",
"prohibited_commodities" : [
"Narcotics",
"Combat Stabilisers",
"Slaves",
"Personal Weapons",
"Battle Weapons",
"Toxic Waste"
],
"faction" : "Empire League",
"has_rearm" : 1,
"allegiance" : "Empire",
"has_refuel" : 1,
"name" : "Smoot Gateway",
"export_commodities" : [
"Water Purifiers",
"Bauxite",
"Rutile"
],
"listings" : [ ],
"distance_to_star" : 4761,
"import_commodities" : [
"Polymers",
"Aluminium",
"Leather"
],
"economies" : [
"Extraction",
"Industrial"
],
"has_repair" : 1
}
],
"name" : "1 G. Caeli",
"faction" : "Empire League",
"government" : "Patronage",
"allegiance" : "Empire",
"updated_at" : 1430931668,
"state" : "None",
"needs_permit" : 0,
"y" : -83.53125,
"x" : 80.90625,
"security" : "Medium",
"z" : -30.8125,
"primary_economy" : "Industrial",
"id" : 1,
"population" : 6544826
}
Commodities: "_id", "name", "average_price", "category"
Systems:
"_id",
"allegiance",
"faction",
"government",
"id",
"name",
"needs_permit",
"population",
"power_control_faction",
"primary_economy",
"security",
"state",
"stations",
"updated_at",
"x",
"y",
"z"
Systems.stations:
"allegiance",
"government",
"has_blackmarket",
"has_commodities",
"has_outfitting",
"has_rearm",
"has_refuel",
"has_repair",
"has_shipyard",
"import_commodities",
"export_commodities",
"max_landing_pad",
"name",
"state",
"updated_at",
quit