Mango::GridFS(3pm) | User Contributed Perl Documentation | Mango::GridFS(3pm) |
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".
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".
my $prefix = $gridfs->prefix; $gridfs = $gridfs->prefix('foo');
Prefix for GridFS collections, defaults to "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 versions of files, positive numbers from 0 and upwards always point to a specific version, negative ones start with "-1" for the most recently added version. 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;
Build 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;
Build 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>.
2020-06-05 | perl v5.30.3 |