Last active
August 29, 2015 14:16
-
-
Save thisismattmiller/7e1ba42724f88411ed2f to your computer and use it in GitHub Desktop.
Python script for querying our MMS MongoDB data
This file contains 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
from pymongo import MongoClient | |
from bson.code import Code | |
import json, re | |
def query(): | |
database = "mms" | |
collection = "mods" | |
address = 'beastmachine.local' | |
#connect to the database | |
client = MongoClient(address) | |
db = client[database] | |
collection = db[collection] | |
#print the count of all collections that have the valueURI but is not empty | |
print collection.find({"mods_name.@valueURI": {"$exists" : True, "$ne" : ""} }).count() | |
#print the number of records that have the word Matthew in the title | |
print collection.find({'mods_titleInfo.title':{'$regex': re.compile('.*Matthew.*') }}).count() | |
#loop through all the data and print each record | |
#for x in collection.find({"mods_name.@valueURI": {"$exists" : True, "$ne" : ""} }): | |
# print json.dumps(x,indent=2) | |
if __name__ == "__main__": | |
query() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment