kraih / mango Goto Github PK
View Code? Open in Web Editor NEW:see_no_evil: Pure-Perl non-blocking I/O MongoDB driver
Home Page: https://metacpan.org/release/Mango
License: Artistic License 2.0
:see_no_evil: Pure-Perl non-blocking I/O MongoDB driver
Home Page: https://metacpan.org/release/Mango
License: Artistic License 2.0
Hi,
Would love to see something like http://mongoosejs.com/ where we can define schema's with optional validation routines and extended attributes/methods on those defined models.
Thanks!
This code:
my $m = Mango->new->db('abc')->collection('xyz');
$m->insert(...)
Gives me this error:
Can't call method "j" on an undefined value at .../perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1/Mango/Database.pm line 14.
However this:
my $mango = Mango->new;
my $m = $mango->db('abc')->collection('xyz');
$m->insert(...)
works just fine.
#!/usr/bin/perl -wl
use Mango;
my $mango = Mango->new;
my $db = $mango->db('test');
$db->gridfs->writer->chunk_size(1)->filename('data.txt')->write('21')->close;
While run this script that save a file in GridFS consisting of two chunks I get the following error.
-- Operation 1 (insert, test.fs.chunks)
-- New connection (localhost:27017:1)
-- Client >>> Server (2)
-- Client <<< Server (2)
-- Operation 3 (insert, test.fs.chunks)
-- Client >>> Server (4)
-- Client <<< Server (4)
-- Operation 5 (insert, test.system.indexes)
-- Client >>> Server (6)
-- Client <<< Server (6)
-- Operation 7 (insert, test.system.indexes)
-- Client >>> Server (8)
-- Client <<< Server (8)
-- Operation 9 (query, test.$cmd, filemd5)
-- Client >>> Server (9)
-- Client <<< Server (9)
exception: assertion src/mongo/db/../bson/bsonelement.h:326 at /home/and/projects/github/mango/lib/Mango/GridFS/Writer.pm line 32.
MongoDB can not calculate the md5 sum of the saved file. I think this is due to the fact that the data in last chunk is Boolean instead BinData.
> db.fs.chunks.find()
{ "n" : 0, "files_id" : ObjectId("52808c35c822c1517a010000"), "_id" : ObjectId("52808c35c822c1517a020000"), "data" : BinData(0,"Mg==") }
{ "n" : 1, "files_id" : ObjectId("52808c35c822c1517a010000"), "_id" : ObjectId("52808c35c822c1517a030000"), "data" : true }
>
It seems chaining cursor commands doesn't work the same way it would in the "official" MongoDB driver, e.g.:
my $cursor = $coll->find({ ... })->sort({ ... })->limit(10);
Results in no data being returned. If you do this:
my $cursor = $coll->find({ ... });
$cursor->sort({ ... });
$cursor->limit({ ... });
It works as expected.
Not a super big deal but maybe worth mentioning in the docs :)
Hello. I think there is a bug (in documentation or in the code).
use Mojo::Base -strict;
use Test::More;
use Mango;
my $mango = Mango->new('mongodb://localhost:27017/test');
$mango->db->collection('fs.files')->remove({});
$mango->db->collection('fs.chunks')->remove({});
my $gridfs = $mango->db->gridfs;
my $writer = $gridfs->writer;
my $reader = $gridfs->reader;
$gridfs->writer->filename('test.txt')->write('First')->close;
$gridfs->writer->filename('test.txt')->write('Latest')->close;
# documentation says that we shoul find the latest version this way
# https://metacpan.org/pod/Mango::GridFS#reader
my $oid = $gridfs->find_version('test.txt', 1);
my $data = $gridfs->reader->open($oid)->slurp;
# fail
is $data, 'Latest', "Got latest content";
If 1 is the latest one, line 34 in Mango::GridFS should be:
$cursor->sort({uploadDate => -1})->limit(-1)->fields({_id => 1});
If 1 means "the first one" and the bug is in documentation, how to load the latest version of file?
Mango v0.22
use Mango;
my $mango = Mango->new('mongodb://localhost:27017');
my $db = $mango->db('test');
my $coll = $db->collection('c');
$coll->insert({"f" => "a" });
my $list = $coll->find()->all();
print scalar @{$list};
#1
print $coll->find()->count();
#0
The count is always returning 0 no matter what;
if length of file < chunk size then result current md5(d41d8cd98f00b204e9800998ecf8427e) alwase. After upload db.runCommand(filemd5: …) - result different hash
Problem!
my $mango = Mango->new('mongodb://localhost:27017');
my $db = $mango->db('test');
say dumper $db->collection_names();
MongoDB wire protocol version 2 required at /usr/share/perl5/Mango/Cursor.pm line 207.
MongoDB version 2.4.9
url_for
sometimes generates wrong url (without .format)
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;
my $t = Test::Mojo->new;
app->routes->route('/path', format => ['json'])->name('name')
->to(cb => sub { shift->render(text => 'hello') });
#$t->get_ok('/path.json')->content_is('hello');
my $url = app->url_for('name', format => 'json');
is $url, '/path.json';
$t->get_ok($url)->status_is('200');
done_testing;
The current default for batch_size
will always preclude using limit
on a query and thus return all results to the cursor.
One must set both batch_size
and limit
on a cursor for either to take effect.
I keep getting this error, but I'm running 2.6.3 on my client. My server is running mongo and mongod version 2.6.3 as well.
What do I need to delete or clean or install to convince it that I'm using 2.6?
For context, I'm 100% new to perl so I might be overlooking something obvious (delete some build folder). Also, both the client and the server recently had earlier versions of mongo (the client had ubuntu's mongo-clients package installed, while the server had the more official (but still outdated) mongo 10gen package installed. I removed + purged all older packages AFAIK, but it's possible there are remenants left
When added a binary values to a collection, I see warnings, which printed endlessly in a loop.
This is caused by a bug in Mango or something deeper?
May be Mango should throw an exception when the bson_bin takes a scalar with the UTF flag?
Example:
#!/usr/bin/perl -wl
use Mango;
use Mango::BSON ':bson';
use utf8;
my $db = Mango->new->db('test');
$db->collection('test')->insert({f => bson_bin('★')});
Output:
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
Write failed: Wide character in syswrite at /home/and/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux/IO/Handle.pm line 480.
...
When I was using Mango in my project something goes wrong when using $cursor->next in a while loop (same as it is done in de code of $cursor->all):
while(my $next = $cursor->next ){ }
It seems to get all documents correctly but when $cursor->next is call at the end of the while loop after the last document, it fails with: assertion src/mongo/s/cursors.cpp:196 at /Users/user/.cpanm/work/1381491736.11366/Mango-0.14/blib/lib/Mango/Cursor.pm line 148
To verify I tried to build Mango 0.14 with ENV{TEST_ONLINE} and the tests fail at the same point. Same issue when building and testing the git master.
make test output: (with TEST_ONLINE='mongodb://localhost')
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/*/*.t
t/bson.t .......... ok
t/collection.t .... assertion src/mongo/s/cursors.cpp:196 at /Users/user/git/mango/blib/lib/Mango/Cursor.pm line 148
t/collection.t .... Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run
t/connection.t .... 1/? assertion src/mongo/s/cursors.cpp:196 at /Users/user/git/mango/blib/lib/Mango/Cursor.pm line 148
# Tests were run but no plan was declared and done_testing() was not seen.
t/connection.t .... Dubious, test returned 255 (wstat 65280, 0xff00)
All 23 subtests passed
t/cursor.t ........ assertion src/mongo/s/cursors.cpp:196 at /Users/user/git/mango/blib/lib/Mango/Cursor.pm line 148
t/cursor.t ........ Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run
t/database.t ...... 4/?
# Failed test 'right name'
# at t/database.t line 33.
# got: undef
# expected: 'admin'
# Failed test 'right name'
# at t/database.t line 47.
# got: undef
# expected: 'admin'
assertion src/mongo/s/cursors.cpp:196 at /Users/user/git/mango/blib/lib/Mango/Cursor.pm line 148
# Tests were run but no plan was declared and done_testing() was not seen.
t/database.t ...... Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 2/6 subtests
t/gridfs.t ........ ok
t/pod.t ........... skipped: set TEST_POD to enable this test (developer only!)
t/pod_coverage.t .. skipped: set TEST_POD to enable this test (developer only!)
t/protocol.t ...... ok
Test Summary Report
-------------------
t/collection.t (Wstat: 65280 Tests: 0 Failed: 0)
Non-zero exit status: 255
Parse errors: No plan found in TAP output
t/connection.t (Wstat: 65280 Tests: 23 Failed: 0)
Non-zero exit status: 255
Parse errors: No plan found in TAP output
t/cursor.t (Wstat: 65280 Tests: 0 Failed: 0)
Non-zero exit status: 255
Parse errors: No plan found in TAP output
t/database.t (Wstat: 65280 Tests: 6 Failed: 2)
Failed tests: 4, 6
Non-zero exit status: 255
Parse errors: No plan found in TAP output
Files=9, Tests=255, 16 wallclock secs ( 0.12 usr 0.06 sys + 2.10 cusr 0.31 csys = 2.59 CPU)
Result: FAIL
Failed 4/9 test programs. 2/255 subtests failed.
make: *** [test_dynamic] Error 255
When using aggregate, count is not working properly.
> db.x.insert({a: 1})
WriteResult({ "nInserted" : 1 })
> db.x.insert({a: 2})
WriteResult({ "nInserted" : 1 })
> db.x.count()
2
> db.x.aggregate([{$match: {a: 1}}])
{ "_id" : ObjectId("5409bc74acf568b885b06c64"), "a" : 1 }
But Mango return 2 instead 1:
$ perl -MMango -le '$c = Mango->new->db("test")->collection("x")->aggregate([{ q{$match} => {a => 1} }])->count; print $c'
2
$
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.