English 中文(简体)
PHP的司机和MongoDB conole使用ne
原标题:Different results from PHP s driver and MongoDB console when using $near
  • 时间:2011-10-06 20:54:56
  •  标签:
  • php
  • mongodb

我会根据我的要求取得不同的结果。 我有一个由2名协调人员组成的“站”收集。

摘自Mongo Console:

> db.stops.find({loc:{$near: [-##.94248402000001,##.444653126]}}).limit(3)
{ "_id" : ObjectId("4e8e0e64597535e4cb0001bd"), "stop_id" : 873198944, "stop_name" : "STOP ONE", "loc" : [ -##.942535, ##.444538 ] }
{ "_id" : ObjectId("4e8e0e66597535e4cb001260"), "stop_id" : 1603800857, "stop_name" : "STOP TWO", "loc" : [ -##.94355, ##.444672 ] }
{ "_id" : ObjectId("4e8e0e66597535e4cb000bb7"), "stop_id" : 3659710794, "stop_name" : "STOP THREE", "loc" : [ -##.94355, ##.444672 ] }

我的购买力平价代码:

$mdb=new Mongo();
$result=$mdb->myapp->stops->find(array( loc =>array( $near =>array(floatval($this->userLongitude),floatval($this->userLatitude)))))->limit(3);

I m new to Mongo, but I m pretty sure that code is right. It returns values... just, the wrong ones. Here s what var_dump(iterator_to_array($result)); outputs:

array
     4e8e0e67597535e4cb002092  => 
        array
         stop_id  => float 373055431
         stop_name  => string  STOP A  (length=34)
         loc  => 
        array
            0 => float -##.937874
            1 => float ##.442722
     4e8e0e64597535e4cb00022d  => 
        array
         stop_id  => float 4245689695
         stop_name  => string  STOP B  (length=32)
         loc  => 
        array
            0 => float -##.937515
            1 => float ##.442692
     4e8e0e67597535e4cb0020af  => 
        array
         stop_id  => float 134217173
         stop_name  => string  STOP C  (length=21)
         loc  => 
        array
            0 => float -##.938965
            1 => float ##.443787

一切都采用[长期、灵活]的形式,如Mongo docs所言。 我不知道造成不同结果的原因,但也许我会把PHP的盘点推到底,而是收集了返回数据。 什么错误?

I ve stripped out the IDs for brevity and changed some of the data that shouldn t matter except for privacy (namely, the ## hide the degrees and the stop names are different— if it s critical to see those, I can edit it, but everything else is untouched.)

EDIT:Solved My code to filter/parse longitude and latitude was also truncating the co-ordinates to only two decimals places. When I used the console directly, there wasn t any truncation going on.

最佳回答

The problem existed in my PHP code. My own fault. See the edit in the original question.

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签