In [1]:
from pymongo import MongoClient
In [2]:
client = MongoClient('localhost:27017')
db = client.bosroul
db.places.find_one()
Out[2]:
In [20]:
def aggregate(pipeline):
return db.places.aggregate(pipeline)
In [22]:
total = db.places.count()
pipeline = {"$match" : {"name" : None}}
results = aggregate(pipeline)
print "Total number of places: {0}".format(total)
print "Number of places without a name: {0}".format(len(results['result']))
In [30]:
pipeline = [{"$match" : {"name" : None}},
{"$unwind" : "$labels"},
{"$group" : {"_id" : "$labels",
"count" : {"$sum" : 1}}},
{"$sort" : {"count" : -1}}]
results = aggregate(pipeline)
results
Out[30]:
Hmm, obvsiously, there are some possible not-so-interesting places in the above list. Post office? I mean, c'mon, right?
However, what if, and just bear with me here, we put something somewhere that said something along the lines of:
"Hey, did a post office come up? Is it kinda far from you? Maybe you should write a letter to someone you haven't seen in a while and then go on an adventure to mail it."
"Was it a fire station? Maybe you could go bring the fellas some 'za, nah mean?"
"We could give you some more suggestions, for example for when ATMs come up, but we figure you get the idea."
I'm going to Heroku, setting up MongoLab, gonna make a little Node.js app (I've never done that before), and see if this thing makes sense. You're welcome to join me. :)