I'm using mongoDB GIS and I have the following simple structure
user {
name : "test",
location: {
type:point,
coordinates: [56.25454, 12.564564 ]
}
}
I want to update the coordinates fields so I tried the followings:
$coordinates = array($x,$y);
$collection->update(array(" name" => $name), array('$set'=> array("location"=> array"coordinates"=> $new_coordinates))); // not working location object expected, location array not in correct format'
$collection->update(array(" pseudo" => $pseudo), array('$set'=> array("location.coordinates"=> array("0"=> $coordinates[0], "1"=>$coordinates[1] ) ))); // not working location object expected, location array not in correct format'
$collection->update(array(" pseudo" => $pseudo), array('$set'=> array("location.coordinates"=> array($coordinates) ))); // works but change the array structure, I get coordinates [ ["x ", " y"] ] which is not accepable
I don't know if I missed something, I've passed the whole day to update a field Please help me figure out where is the problem???
Baraa Mohamad wrote:
> I'm using mongoDB GIS and I have the following simple structure
>
> user {
> name : "test",
>
> location: {
> type:point,
> coordinates: [56.25454, 12.564564 ]
> }
> }
<snip>
> $collection->update(array(" pseudo" => $pseudo), array('$set'=>
> array("location.coordinates"=> array($coordinates) ))); // works but change
> the array structure, I get coordinates [ ["x ", " y"] ] which is not
> accepable
I don't know where the x and y come from, but this is the correct
syntax. You do need to make sure that the first value is the *longitude*
and the second one the *lattitude*. I think you might have them the
wrong way around.
> I'm using mongoDB GIS and I have the following simple structure
>
> user {
> name : "test",
>
> location: {
> type:point,
> coordinates: [56.25454, 12.564564 ]
> }
> }
<snip>
> $collection->update(array("
> array("location.coordinates"=> array($coordinates) ))); // works but change
> the array structure, I get coordinates [ ["x ", " y"] ] which is not
> accepable
I don't know where the x and y come from, but this is the correct
syntax. You do need to make sure that the first value is the *longitude*
and the second one the *lattitude*. I think you might have them the
wrong way around.
댓글 없음:
댓글 쓰기