Database Reference
In-Depth Information
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.
The search command works exactly as you would expect. All you need to do is tell mongofiles what you are
looking for, and it will try to find it for you, as in this example:
$ mongofiles search hello
connected to: 127.0.0.1
/tmp/hello_world 4953699
$ mongofiles search dict
connected to: 127.0.0.1
/tmp/dictionary 4953699
$
Again, nothing too exciting happens here. However, there is an important takeaway that's worth noting.
MongoDB can be as simple or as complex as you need it to be. The mongofiles tool is only for reference use, and it
includes very basic debugging. The good news: MongoDB makes it easy to perform simple searches against your files.
The even better news: MongoDB also has your back if you want to write some insanely complicated searches.
Deleting
The mongofiles command delete doesn't require much explanation, but it does deserve a big warning. This
command deletes files based on the filename. Thus, if you have more than one file with the same name, this
command will delete all of them. The following snippet shows how to use the delete command:
$ mongofiles delete /tmp/hello_world
connected to: 127.0.0.1
$ mongofiles list
connected to: 127.0.0.1
/tmp/dictionary 4953699
$
 
Search WWH ::




Custom Search