def showoff_databases(): """ Here we illustrate basic interaction with nosql databases """ log = utilities.configure_logger('default', '../logs/nosql_dev.log') log.info("Mongodb example to use data from Furniture module, so get it") furniture = learn_data.get_furniture_data() roygbiv = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"] for item in furniture: product_type = item['product'] color_name = 'N/A' for color in roygbiv: if color in product_type: color_name = color product_type = product_type.replace(color, '').lstrip(' ') break item['color'] = color_name item['product type'] = product_type mongodb_script.run_example(furniture) log.info("Other databases use data embedded in the modules") redis_script.run_example() neo4j_script.run_example() simple_script.run_example(furniture) persistence_serialization.run_json()
def showoff_databases(): """ Here we illustrate basic interaction with nosql databases """ log = utilities.configure_logger('default', '../logs/nosql_dev.log') log.info( "\n\n\nMongodb example to use data from Furniture module, so get it.") furniture = learn_data.get_furniture_data() log.info("\n\n\nHere's the MongoDB script.") mongodb_script.run_example(furniture) log.info("Other databases use data embedded in the modules") log.info("\n\n\nHere's the Redis script.") redis_script.run_example() log.info("\n\n\nHere's the Neo4J script.") neo4j_script.run_example() log.info( "\n\n\nHere's the persistence/serialization (Pickle/Shelve) script.") simple_script.run_example(furniture)
def showoff_databases(): """ Here we illustrate basic interaction with nosql databases """ log = utilities.configure_logger('default', '../logs/nosql_dev.log') log.info("Mongodb example to use data from Furniture module, so get it") mongo_furniture = learn_data.get_furniture_data() simple_furniture = learn_data.get_furniture_data() mongodb_script.run_example(mongo_furniture) log.info("Other databases use data embedded in the modules") redis_script.run_example() neo4j_script.run_example() simple_script.run_example(simple_furniture)
def run_exercises(): """ run exercises for lesson 8 assignment """ log = utilities.configure_logger('default', '../logs/nosql_dev.log') log.info("Mongodb exercise") furniture = learn_data.get_furniture_data() mongodb_script.run_exercise(furniture) log.info("Redis exercise") redis_script.run_exercise() log.info("Neo4j exercise") neo4j_script.run_exercise() log.info("Persistence exercise: json and csv") simple_script.run_exercise()
def showoff_databases(): """ Here we illustrate basic interaction with nosql databases """ log = utilities.configure_logger('default', '../logs/nosql_dev.log') # log.info("Mongodb example to use data from Furniture module, so get it") furniture = learn_data.get_furniture_data() # mongodb_script.run_example(furniture) # log.info("Other databases use data embedded in the modules") # redis_script.run_example() # neo4j_script.run_example() # simple_script.run_example(furniture) # log.info("Folloing are for the lesson 08 exercise") # log.info("Here is an application of monogodb") # mongodb_script.run_nosql_ex(furniture) log.info("Here is an application of redis") redis_script.run_nosql_ex()
log.info('Step 4: Print the Red items') print('Red products:') for doc in cursor: print( f"Color: {doc['color']} product name: {doc['product']} Description: {doc['description']}" ) log.info( 'Step 7: Find multiple documents, iterate though the results and print' ) cursor = furniture.find({'product': {'$eq': 'couch'}}) print('Results of search') log.info('Notice how we parse out the data from the document') print('Couches:') for doc in cursor: print( f"Product name: {doc['product']} Color: {doc['color']} Description: {doc['description']}" ) log.info('Step 8: Delete the collection so we can start over') db.drop_collection('furniture') if __name__ == "__main__": furn_dict = learn_data.get_furniture_data() run_example(furn_dict)
log.info('Step 8: Add two more furnitures to the database') furniture.insert_many(additional_furniture) query_new = {'in_stock_quantity': 15} results_new = furniture.find(query_new) print('Two additional furnitures have been added:') for new_item in results_new: pprint.pprint(new_item) log.info('Step 9: Print just the red products') query_red = furniture.find({'product_color': 'Red'}) for red in query_red: pprint.pprint(red) log.info('Step 10: Print just the couch products') log.info( 'Adding the blue couch that was removed in step 5 back into the db' ) furniture.insert_one(blue_couch) query_couch = furniture.find({'product': 'Couch'}) for couch in query_couch: pprint.pprint(couch) log.info('Step 11: Delete the collection so we can start over') db.drop_collection('furniture') if __name__ == '__main__': furniture = learn_data.get_furniture_data() run_example(furniture)