Database Reference
In-Depth Information
Working with GridFS
Next, we'll take a brief look at how GridFS is implemented. As the MongoDB website
points out, you do not need to understand or be aware of the underlying implementation
of GridFS to use it. In fact, you can simply let the driver handle the heavy lifting for you.
For the most part, the drivers that support GridFS implement file handling in a language-
specific way. For example, the MongoDB driver for Python works in a manner that is
wholly consistent with Python, as you'll see shortly. If the ins-and-outs of GridFS don't
interest you, then just skip ahead to the next section. We promise you won't miss anything
that enables you to use MongoDB effectively!
GridFS consists of two parts. More specifically, it consists of two collections. One
collection holds the filename and related information such as size (called metadata),
while the other collection holds the file data itself, usually in 256K chunks. The
specification calls for these to be named files and chunks , respectively. By default, the
files and chunks collections are created in the fs namespace, but this can be changed.
The ability to change the default namespace is useful if you want to store different types of
files. For example, you might want to keep image and movie files separate.
Getting Started with the Command-Line Tools
Now that we have some of the background out of the way, let's look at how to get started
with GridFS by exploring the command-line tools available to leverage it. First, we will
need a file to play with. To keep things simple, let's use the dictionary file. On Ubuntu, you
can find this at /usr/share/dict/words . However, there are various levels of symbolic
links, so you might want to run this command first:
root@core2:/usr/share/dict# cat words > /tmp/dictionary
In Ubuntu, you might need to use apt-get install wbritish to get the
dictionary file installed.
Note
This command copies all the contents of the file to a nice and simple path that you
can use easily. Of course, you can use any file that you wish for this example; it doesn't
need to be any particular size or type.
Rather than describe all the options you can use with, let's jump right in and
start playing with some of the tool's features. This topic assumes that you're running
mongofiles on the same machine as MongoDB. If you're not, then you'll need to use the
-h option to specify the host that MongoDB is running on. You'll learn about the other
options available in the mongofiles command after putting it through its paces.
 
 
Search WWH ::




Custom Search