Database Reference
In-Depth Information
Tutorial Links
The tutorials section on the official project page is a great place to get started. There are also
plenty of videos available on the Internet, including this informative series .
Example Code
This time you'll want to compute the average ranking of the movie Dune in the standard
dataset. If you know Python, this will be clear. If you don't, the code is still pretty straight-
forward:
#!/usr/bin/python
# import required packages
import
import sys
sys
import
import pymongo
pymongo
# json movie reviews
movieReviews = [
{ "reviewer" : "Kevin" , "movie" : "Dune" , "rating" , "10" },
{ "reviewer" : "Marshall" , "movie" : "Dune" , "rating" , "1" },
{ "reviewer" : "Kevin" , "movie" : "Casablanca" , "rating" , "5" },
{ "reviewer" : "Bob" , "movie" : "Blazing Saddles" , "rating" , "9" }
]
# MongoDB connection info
MONGODB_INFO = 'mongodb://juser:password@localhost:27018/db'
# connect to MongoDB
client = pymongo . MongoClient ( MONGODB_INFO )
db = client . get_defalut_database ()
# create the movies collection
movies = db [ 'movies' ]
#insert the movie reviews
movies . insert ( movieReviews )
# find all the movies with title Dune, iterate through them
# finding all scores by using
# standard db cursor technology
mcur = movies . find ({ 'movie' : { 'movie' : 'Dune' })
count = 0
sum = 0
Search WWH ::




Custom Search