Pergunta

this sorted correctly when using directly

db.users.find({currentloc : {$nearSphere : [115.22804,-8.69914]}})

but when execute from PHP, it look like sorted by _id

$users = $this->m->mappt->users;
$results = $users->find(
    array(
        'currentloc' => array('$nearSphere' => array(115.22804,-8.69914))

    );
$arrayresult = iterator_to_array($results);

any ideas ?

Foi útil?

Solução

Your query looks fine. I can think of a few things:

  • You don't have a 2dsphere index, which you do have from the shell
  • iterator_to_array() is messing with it — if you do a normal foreach() do you get them in the right order then?

Outras dicas

Adi, You can get idea from Here. You can try to use variable name for geo values.

Other try like this,

$collection->find(Array("point" => Array('$within' => Array('$center'=> Array(Array(151.1955562233925,-33.87107475181752), 0.1/111 ) ) )));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top