NAME

Mango::GridFS - GridFS

SYNOPSIS

use Mango::GridFS;

my $gridfs = Mango::GridFS->new(db => $db);
my $reader = $gridfs->reader;
my $writer = $gridfs->writer;

DESCRIPTION

Mango::GridFS is an interface for MongoDB GridFS access.

ATTRIBUTES

Mango::GridFS implements the following attributes.

chunks

my $chunks = $gridfs->chunks;
$gridfs    = $gridfs->chunks(Mango::Collection->new);

Mango::Collection object for chunks collection, defaults to one based on "prefix".

db

my $db  = $gridfs->db;
$gridfs = $gridfs->db(Mango::Database->new);

Mango::Database object GridFS belongs to.

files

my $files = $gridfs->files;
$gridfs   = $gridfs->files(Mango::Collection->new);

Mango::Collection object for files collection, defaults to one based on "prefix".

prefix

my $db  = $gridfs->prefix;
$gridfs = $gridfs->prefix('foo');

Prefix for GridFS collections, defaults to fs.

METHODS

Mango::GridFS inherits all methods from Mojo::Base and implements the following new ones.

delete

$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;

find_version

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;

list

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;

reader

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" }

writer

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;

SEE ALSO

Mango, Mojolicious::Guides, http://mojolicio.us.