1Mango::GridFS(3)      User Contributed Perl Documentation     Mango::GridFS(3)
2
3
4

NAME

6       Mango::GridFS - GridFS
7

SYNOPSIS

9         use Mango::GridFS;
10
11         my $gridfs = Mango::GridFS->new(db => $db);
12         my $reader = $gridfs->reader;
13         my $writer = $gridfs->writer;
14

DESCRIPTION

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

ATTRIBUTES

19       Mango::GridFS implements the following attributes.
20
21   chunks
22         my $chunks = $gridfs->chunks;
23         $gridfs    = $gridfs->chunks(Mango::Collection->new);
24
25       Mango::Collection object for "chunks" collection, defaults to one based
26       on "prefix".
27
28   db
29         my $db  = $gridfs->db;
30         $gridfs = $gridfs->db(Mango::Database->new);
31
32       Mango::Database object GridFS belongs to.
33
34   files
35         my $files = $gridfs->files;
36         $gridfs   = $gridfs->files(Mango::Collection->new);
37
38       Mango::Collection object for "files" collection, defaults to one based
39       on "prefix".
40
41   prefix
42         my $prefix = $gridfs->prefix;
43         $gridfs    = $gridfs->prefix('foo');
44
45       Prefix for GridFS collections, defaults to "fs".
46

METHODS

48       Mango::GridFS inherits all methods from Mojo::Base and implements the
49       following new ones.
50
51   delete
52         $gridfs->delete($oid);
53
54       Delete file. You can also append a callback to perform operation non-
55       blocking.
56
57         $gridfs->delete($oid => sub {
58           my ($gridfs, $err) = @_;
59           ...
60         });
61         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
62
63   find_version
64         my $oid = $gridfs->find_version('test.txt', 1);
65
66       Find versions of files, positive numbers from 0 and upwards always
67       point to a specific version, negative ones start with "-1" for the most
68       recently added version. You can also append a callback to perform
69       operation non-blocking.
70
71         $gridfs->find_version(('test.txt', 1) => sub {
72           my ($gridfs, $err, $oid) = @_;
73           ...
74         });
75         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
76
77   list
78         my $names = $gridfs->list;
79
80       List files. You can also append a callback to perform operation non-
81       blocking.
82
83         $gridfs->list(sub {
84           my ($gridfs, $err, $names) = @_;
85           ...
86         });
87         Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
88
89   reader
90         my $reader = $gridfs->reader;
91
92       Build Mango::GridFS::Reader object.
93
94         # Read all data at once from newest version of file
95         my $oid  = $gridfs->find_version('test.txt', -1);
96         my $data = $gridfs->reader->open($oid)->slurp;
97
98         # Read all data in chunks from file
99         my $reader = $gridfs->reader->open($oid);
100         while (defined(my $chunk = $reader->read)) { say "Chunk: $chunk" }
101
102   writer
103         my $writer = $gridfs->writer;
104
105       Build Mango::GridFS::Writer object.
106
107         # Write all data at once to file with name
108         my $oid = $gridfs->writer->filename('test.txt')->write('Hello!')->close;
109
110         # Write data in chunks to file
111         my $writer = $gridfs->writer;
112         $writer->write($_) for 1 .. 100;
113         my $oid = $writer->close;
114

SEE ALSO

116       Mango, Mojolicious::Guides, <http://mojolicio.us>.
117
118
119
120perl v5.36.0                      2022-07-22                  Mango::GridFS(3)
Impressum