December 2015
Beginner to intermediate
202 pages
4h
English
In order to produce a list view on a web page, or to pull more than a single record out of MongoDB, say, for analysis, you will need to query for multiple records.
PyMongo provides a find() function that we can use to search for multiple documents that match a given criteria, returning a cursor instance that we can iterate over.
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.pythonbicookbook
accidents = db.accidents
# Retrieve all records where the accident happened on a Friday
data = accidents.find({"Day_of_Week": 7})
# Show a count for the result
data.count() # returns 896218The find() function is a powerful method for filtering ...
Read now
Unlock full access