Storing data to GridFS from Java client
In the previous recipe, we saw how to store data to GridFS using a command-line utility that comes with MongoDB to manage large data files: mongofiles. To get an idea of what GridFS is and what collections are used behind the scenes to store the data, refer to the previous recipe Storing large data in Mongo using GridFS.
In this recipe, we will look at storing data to GridFS using a Java client. The program will be a highly scaled down version of mongofiles utility and focus only on how to store, retrieve, and delete data rather than trying to provide a lot of options like mongofiles do.
Getting ready
Refer to the recipe Installing single node MongoDB from Chapter 1, Installing and Starting the Server, for all the necessary setup for this recipe. If you are interested in more details on Java drivers, refer to the recipes Implementing aggregation in Mongo using a Java client and Executing MapReduce in Mongo using a Java client in Chapter 3, Programming...