Retrieving a single record is a common operation in any system with the CRUD (Create Read Update Delete) functionality.
PyMongo has a method that allows us to easily query a single record using zero or more criteria: find_one()
.
from pymongo import MongoClient client = MongoClient('localhost', 27017) db = client.pythonbicookbook accidents = db.accidents # Find the first document in the collection accidents.find_one() # Find the first document in the collection where the accident happened on a Sunday accidents.find_one({"Day_of_Week": 1})