I have the following code running in a perl Mojolicious app. The collection it runs against has a 2d index applied to the "loc" property which is 2 element array of the form [ lat, long ].
MongoDB is 2.0.1, perl MongoDB is 0.46. perl is 64bit
I have no trouble pushing inserting/upserting new documents when the 2d index has been dropped. When the index is applied, last_error returns "location object expected, location array not in correct format"
I've tried manipulating the lat and long input multiple ways, to no avail. Here is the code ... any ideas?
sub checkmein {
my $self = shift;
my $mail = $self->stash('mail');
my $lat = $self->param('lat');
my $lng = $self->param('long');
# upsert
my $c = $self->db->checkins;
$mail = lc $mail;
my $now = time;
my @loc = (Math::BigFloat->new($lng),Math::BigFloat->new($lat));
$c->update(
{'mail'=>$mail },
{ 'mail'=>$mail, 'when'=>$now, 'loc'=>\@loc },
{ upsert=>1 }
);
my $err = $self->db->last_error();
if (defined $err->{'err'}) {
$self->render(json=>{'status'=>'error','message'=>"Problem checking in $mail to $lat,$lng"});
} else {
$self->render(json=>{'status'=>'ok','message'=>"$mail checked in to $lat,$lng"});
}
}
evalcan't even compile. Your MongoDB (and MongoDB driver) are also seriously out-of-date, though that's not related to your problem.