VERSION

SYNOPSIS

There are two interfaces for GridFS: a file-system/collection-like interface (insert, remove, drop, find_one) and a more general interface (get, put, delete). Their functionality is the almost identical (get, put and delete are always safe ops, insert, remove, and find_one are optionally safe), using one over the other is a matter of preference.

delete($id)

Removes the file with the given _id. Will die if the remove is unsuccessful. Does not return anything on success.

find_one ($criteria?, $fields?)

my $file = $grid->find_one({"filename" => "foo.txt"});

Returns a matching MongoDB::GridFS::File or undef.

remove ($criteria?, $options?)

$grid->remove({"filename" => "foo.txt"});

Cleanly removes files from the database. $options is a hash of options for the remove. Possible options are:

just_one If true, only one file matching the criteria will be removed.

safe If true, each remove will be checked for success and die on failure.

This method doesn't return anything.

insert ($fh, $metadata?, $options?)

my $id = $gridfs->insert($fh, {"content-type" => "text/html"});

Reads from a file handle into the database. Saves the file with the given metadata. The file handle must be readable. $options can be {"safe" = true}>, which will do safe inserts and check the MD5 hash calculated by the database against an MD5 hash calculated by the local filesystem. If the two hashes do not match, then the chunks already inserted will be removed and the program will die.

Because MongoDB::GridFS::insert takes a file handle, it can be used to insert very long strings into the database (as well as files). $fh must be a FileHandle (not just the native file handle type), so you can insert a string with: