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 | |
# pprint library is used to make the output look more pretty | |
from pprint import pprint | |
# connect to MongoDB, change the << MONGODB URL >> to reflect your own connection string | |
client = MongoClient(<<MONGODB URL>>) | |
db=client.admin | |
# Issue the serverStatus command and print the results | |
serverStatusResult=db.command("serverStatus") | |
pprint(serverStatusResult) |
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 | |
#include pprint for readabillity of the | |
from pprint import pprint | |
#change the MongoClient connection string to your MongoDB database instance | |
client = MongoClient(port=27020) | |
db=client.business | |
ASingleReview = db.reviews.find_one({}) | |
print('A sample document:') |
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 | |
# Connect to the MongoDB, change the connection string per your MongoDB environment | |
client = MongoClient(port=27017) | |
# Set the db object to point to the business database | |
db=client.business | |
# Showcasing the count() method of find, count the total number of 5 ratings | |
print('The number of 5 star reviews:') | |
fivestarcount = db.reviews.find({'rating': 5}).count() | |
print(fivestarcount) | |
# Not let's use the aggregation framework to sum the occurrence of each rating across the entire data set |
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 random import randint | |
#Step 1: Connect to MongoDB - Note: Change connection string as needed | |
client = MongoClient(port=27017) | |
db=client.business | |
#Step 2: Create sample data | |
names = ['Kitchen','Animal','State', 'Tastey', 'Big','City','Fish', 'Pizza','Goat', 'Salty','Sandwich','Lazy', 'Fun'] | |
company_type = ['LLC','Inc','Company','Corporation'] | |
company_cuisine = ['Pizza', 'Bar Food', 'Fast Food', 'Italian', 'Mexican', 'American', 'Sushi Bar', 'Vegetarian'] | |
for x in xrange(1, 501): |
NewerOlder