I'm trying to insert a record that contains a nested array of geospatial data. I've even tried making the array an object instead, but no luck there either. Here's more or less the insert line:
$collection->insert($obj, array('safe'=>true));
One interesting thing is that when I call the index 'loc' something else, such as just an integer, the insert works.
Here's the array that should be going into Mongodb, but isn't:
Array
(
[name] => Home
[address] => 500 Pole Line Road
[city] => Davis
[state] => CA
[zip] => 95618
[loc] => Array
(
[lon] => -121.726710
[lat] => 38.549576
)
)
MongoDB doesn't care about the keys for a geospational "field". It just takes the first two elements with the first one being longitude, and the second lattitude. Even if you'd name your first one "lat" it would still be seen as the longitude. The only reason why I could think it would not insert is perhaps you have a unique key on some fields.
If you'd add a full working (but small) example of what you're inserting, then I can update the answer to hopefully show what is wrong.
array( 'loc' => array( floatval($lon), floatval($lat)))