Database Reference
In-Depth Information
You might wonder why the output here has so many entries. As noted previously,
GridFS is just a specification. That is, it uses what MongoDB already provides. While
we were testing the commands for the topic, the dictionary file was added a couple of
times. Later, this file was deleted when we emptied the fs.files collection. You can
see for yourself what happened next! The fact that some documents were removed
from a collection has no bearing on what happens in another collection. Remember:
MongoDB doesn't treat these documents or collections in any special way. If the file had
been deleted properly through a driver or the mongofiles tool, that tool would also have
cleaned up the chunks collection.
accessing documents and collections directly is a powerful feature, but you
need to be careful. This feature also makes it much easier to shoot yourself in both feet
at the same time. Make sure you know what you're doing and that you perform a great
deal of testing if you decide to edit these documents and collections manually. also, keep
in mind that the GridFS support in MongoDB's drivers won't know anything about any
customizations that you've made.
Warning
Using the search Command
Next, let's take a closer look at MongoDB's search command. Thus far, there is only a
single file in the database, which greatly limits the types of searches you might conduct!
So let's add something else. The following snippet copies the dictionary to another file,
and then imports that file:
$ cp /tmp/dictionary /tmp/hello_world
$ mongofiles put /tmp/hello_world
connected to: 127.0.0.1
added file: { _id: ObjectId('51cb63d167961ebc919edbd5'), filename: "/tmp/
hello_world", chunkSize: 262144, uploadDate: new Date(1372283858021), md5:
"40c0825855792bd20e8a2d515fe9c3e3", length: 4953699 }done!
root@core2:~# mongofiles list
connected to: 127.0.0.1
/tmp/dictionary 4953699
/tmp/hello_world 4953699
$
The first line copies the file, and the second line imports it into MongoDB. As in
the earlier example, the put command prints out the new document that MongoDB has
created. Next, you might run the mongofiles command list to check that the files were
correctly stored. If you do so, you can see that there are now two files in the collection;
unsurprisingly, both files have the same size.
 
 
Search WWH ::




Custom Search