Mango::GridFS - GridFS
use Mango::GridFS; my $gridfs = Mango::GridFS->new(db => $db); my $reader = $gridfs->reader; my $writer = $gridfs->writer;
Mango::GridFS is an interface for MongoDB GridFS access.
Mango::GridFS implements the following attributes.
my $chunks = $gridfs->chunks; $gridfs = $gridfs->chunks(Mango::Collection->new);
Mango::Collection object for chunks collection, defaults to one based on prefix.
chunks
prefix
my $db = $gridfs->db; $gridfs = $gridfs->db(Mango::Database->new);
Mango::Database object GridFS belongs to.
my $files = $gridfs->files; $gridfs = $gridfs->files(Mango::Collection->new);
Mango::Collection object for files collection, defaults to one based on prefix.
files
my $db = $gridfs->prefix; $gridfs = $gridfs->prefix('foo');
Prefix for GridFS collections, defaults to fs.
fs
Mango::GridFS inherits all methods from Mojo::Base and implements the following new ones.
$gridfs->delete($oid);
Delete file. You can also append a callback to perform operation non-blocking.
$gridfs->delete($oid => sub { my ($gridfs, $err) = @_; ... }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
my $oid = $gridfs->find_version('test.txt', 1);
Find a specific version of a file. You can also append a callback to perform operation non-blocking.
$gridfs->find_version(('test.txt', 1) => sub { my ($gridfs, $err, $oid) = @_; ... }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
my $names = $gridfs->list;
List files. You can also append a callback to perform operation non-blocking.
$gridfs->list(sub { my ($gridfs, $err, $names) = @_; ... }); Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
my $reader = $gridfs->reader;
Get Mango::GridFS::Reader object.
# Read all data at once from newest version of file my $oid = $gridfs->find_version('test.txt', 1); my $data = $gridfs->reader->open($oid)->slurp; # Read all data in chunks from file my $reader = $gridfs->reader->open($oid); while (defined(my $chunk = $reader->read)) { say "Chunk: $chunk" }
my $writer = $gridfs->writer;
Get Mango::GridFS::Writer object.
# Write all data at once to file with name my $oid = $gridfs->writer->filename('test.txt')->write('Hello!')->close; # Write data in chunks to file my $writer = $gridfs->writer; $writer->write($_) for 1 .. 100; my $oid = $writer->close;
Mango, Mojolicious::Guides, http://mojolicio.us.
To install Mango, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mango
CPAN shell
perl -MCPAN -e shell install Mango
For more information on module installation, please visit the detailed CPAN module installation guide.