Hello:
I am using Mango in a real (but non-critical) environment. A very, very
successful experience.
Now I want to improve it with error management. The first is a nice ajax alert
when trying to remove a record that does't exist.
First try:
my $doc = $mango->db('test')->collection('foo')->remove({_id => $id});
If the remove operation is OK, the hash in $doc contains:
n = 1
ok = 1
If I try to remove it again, as the record is gone, I get:
n = 0
ok = 1
I presume that the value of "ok" is related to the Mango operation itself, and
"n" is the number of rows modified, or something like that.
Second try:
Using the event error, as seen in the docs:
my $mango = Mango->new('mongodb://localhost:27017');
$mango->on(error => sub {
my ($mango, $err) = @_;
$self->render(json => {result => 'KO ' . $err })
});
my $doc = $mango->db('test')->collection('foo')->remove({_id => $id});
But nothing happens. The documentation say: "Emitted if an error occurs that
can't be associated with an operation." So, it seems that there is no error,
even if there is no record to remove.
Third try:
I tried the non-blocking approach, to wee what is in the $err variable:
my $doc = $collection->remove( ( {_id => $id}, {single => 1} ) => sub {
my ($collection, $err, $doc) = @_;
$self->render(json => {result => 'OK ' . $collection });
}
} );
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
But I always get "premature connection close". And it seems to be a messsage
form IOLoop
Can someone point me in the right direction?
Regards:
Nacho B
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.