Mango::GridFS(3pm)
π Mango::GridFS β the manual, but make it cute π
okay bestie, so this is Mango::GridFS(3pm), straight out of the User Contributed Perl Documentation pile. it's giving "GridFS" and honestly? we ate. let's get into it π«Ά
β¨ NAME β¨
Mango::GridFS β literally just GridFS. that's the whole name. iconic.
β¨ SYNOPSIS β¨
use Mango::GridFS;
my $gridfs = Mango::GridFS->new(db => $db);
my $reader = $gridfs->reader;
my $writer = $gridfs->writer;
look at that. three lines and you're already in your GridFS era. slay π
β¨ DESCRIPTION β¨
so Mango::GridFS is an interface for MongoDB GridFS access. that's it. that's the vibe. no cap, that's the entire description, and honestly sometimes less is more, periodt. π¦
β¨ ATTRIBUTES β¨
Mango::GridFS implements the following attributes. yes bestie, all of them, we're listing every single one πΈ
π chunks
my $chunks = $gridfs->chunks;
$gridfs = $gridfs->chunks(Mango::Collection->new);
this is a Mango::Collection object for the "chunks" collection, and by default it's one based on "prefix". so like, if you don't set it, it just vibes off your prefix. lowkey elegant π
π db
my $db = $gridfs->db;
$gridfs = $gridfs->db(Mango::Database->new);
the Mango::Database object that GridFS belongs to. your GridFS has a home, and this is it π
π files
my $files = $gridfs->files;
$gridfs = $gridfs->files(Mango::Collection->new);
Mango::Collection object for the "files" collection β defaults to one based on "prefix", same deal as chunks. twinning fr fr π
π prefix
my $prefix = $gridfs->prefix;
$gridfs = $gridfs->prefix('foo');
the prefix for your GridFS collections. defaults to "fs". change it if you wanna be different, no judgment β¨
β¨ METHODS β¨
Mango::GridFS inherits all methods from Mojo::Base and implements the following new ones. so it's got the family genes AND its own main character moments π
π¦ delete
$gridfs->delete($oid);
delete a file. and because we love options, you can also append a callback to perform the operation non-blocking. go off, async queen π
$gridfs->delete($oid => sub {
my ($gridfs, $err) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
don't forget the Mojo::IOLoop->start unless Mojo::IOLoop->is_running; line, bestie β that's the part everyone forgets and then wonders why nothing happens π
π¦ find_version
my $oid = $gridfs->find_version('test.txt', 1);
find versions of files! here's the tea: positive numbers from 0 and upwards always point to a specific version, and negative ones start with "-1" for the most recently added version. so -1 is the freshest, 0 and up are the numbered ones. got it? got it π
and yes, you can also append a callback to perform the 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 your files. simple, clean, we love her. and β you guessed it β you can append a callback to perform the operation non-blocking:
$gridfs->list(sub {
my ($gridfs, $err, $names) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
π¦ reader
my $reader = $gridfs->reader;
build a Mango::GridFS::Reader object. here's how you use it, two whole ways β¨
# 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" }
one-shot slurp if you're feeling impatient, chunk-by-chunk if you're feeling β¨methodicalβ¨. both valid, both iconic π§
π¦ writer
my $writer = $gridfs->writer;
build a Mango::GridFS::Writer object. and look at these two gorgeous examples π
# 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;
chained one-liner? obsessed. loop-and-write? also obsessed. notice both paths end in close, and close is what hands you your $oid. don't skip the close, bestie, that's where the magic happens π₯
β¨ SEE ALSO β¨
MangoMojolicious::Guides- <http://mojolicio.us>
go read those too, iykyk π
π heads up: the docs spell it <http://mojolicio.us> and i am NOT touching that, that's exactly what it says, i don't make the rules π
and that's the whole page, bestie!! this was perl v5.30.3, dated 2020-06-05, and it's Mango::GridFS(3pm) β go forth and GridFS responsibly πΈπβ¨
π¦ where this page comes from
- debian bookworm: libmango-perl 1.30-2 Β· Artistic-2.0
- debian trixie: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu jammy: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu noble: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu resolute: libmango-perl 1.30-2 Β· Artistic-2.0
- ubuntu stonking: libmango-perl 1.30-2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms