Install MongoDB and Python wrapper (Ubuntu Linux)
sudo apt-get install -y mongodb-org
pip install pymongo
pip3 install pymongo
mongod
# or:
# service mongod start
mongoimport --db db_name_here --collection collection_name_here --file /path/to/BSON_file.bson
Initialize MongoDB in Python
from pymongo import MongoClient
from pprint import pprint
client = MongoClient ()
records = client .db_name_here .collection_name_here
Search for exact creator name
cursor = records .find ({ 'pbcoreDescriptionDocument.pbcoreCreator.creator' : "Worden, Michelle" })
for item in cursor :
print (item )
Search for exact program title
cursor = records .find ({ 'pbcoreDescriptionDocument.pbcoreTitle.#text' : "Grace: A Tribute to Pope John Paul II" })
for item in cursor :
print (item )
Search for records containing "Music" as a genre
cursor = records .find ({ 'pbcoreDescriptionDocument.pbcoreGenre.#text' : "Music" })
for item in cursor :
print (item )
Search for records that include "Arkansas" in description
cursor = records .find ({ 'pbcoreDescriptionDocument.pbcoreDescription.#text' : {'$regex' :'.*Arkansas.*' }})
for item in cursor :
print (item )