Thanks. I started to realize it just while writing the question..., but in
my third approach, the non blocking one:
- The remove action is not actually performed
- The value of $err is always "*premature connection close*"".
This is my action. It is called through Ajax using DELETE. The AJAX
response, with the value of $err, arrives perfectly. So it seems that I am
doing something wrong in the non-blocking call to "remove", isn`t it?
use Mango;
use Mango::BSON ':bson';
use Mojo::IOLoop;
sub remove2 {
my $self = shift;
my $id = bson_oid $self->stash('id');
$self->render_later;
my $mango = Mango->new('mongodb://localhost:27017');
$mango->db('test')->collection('foo')->remove( ({_id => $id}, {single =>
1}) => sub {
my ($collection, $err, $doc) = @_;
$self->render(json => {result => 'Message ' . $err });
} );
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
}
And this is the log output:
[Fri Jun 20 18:26:30 2014] [debug] DELETE "/shop/53a45fd264081402d1020000".
[Fri Jun 20 18:26:30 2014] [debug] Routing to controller "PWCTester::User"
and action "auth".
[Fri Jun 20 18:26:30 2014] [debug] Routing to controller "PWCTester::Shop"
and action "remove2".
[Fri Jun 20 18:26:30 2014] [debug] 200 OK (0.001687s, 592.768/s).
Regards:
Nacho B
On Friday, June 20, 2014 4:07:35 PM UTC+2, sri wrote:
>
> 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.
>>
>
> Almost all errors come directly from MongoDB, "no record to remove" is
> simply not an error condition.
>
> --
> sebastian
>
--
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.