Storing data to GridFS from Python client
In the recipe Storing large data in Mongo using GridFS, we saw what GridFS is and how it could be used to store the large files in MongoDB. In the previous recipe, we saw to use GridFS API from a Java client. In this recipe, we will see how to store image data into MongoDB using GridFS from a Python program.
Getting ready
Refer to the recipe Connecting to the single node using a Java client from Chapter 1, Installing and Starting the Server, for all the necessary setup for this recipe. If you are interested in more detail on Python drivers refer to the following recipes: Executing query and insert operations with PyMongo and Executing update and delete operations using PyMongo in Chapter 3, Programming Language Drivers. Download and save the image glimpse_of_universe-wide.jpg
from the downloadable bundle available with the book from the Packt site to local filesystem as we did in the previous recipe.
How to do it…
Open a Python interpreter by typing...