我在 PHP 中插入带有地理空间数据的 Mongodb 记录时遇到问题
我正在尝试插入包含地理空间数据嵌套数组的记录。我什至尝试将数组变成一个对象,但也没有运气。或多或少是插入行:
$collection->insert($obj, array('safe'=>true));
一件有趣的事情是,当我将索引“loc”称为其他名称(例如整数)时,插入会起作用。
这是应该进入 Mongodb 但没有进入的数组:
Array
(
[name] => Home
[address] => 500 Pole Line Road
[city] => Davis
[state] => CA
[zip] => 95618
[loc] => Array
(
[lon] => -121.726710
[lat] => 38.549576
)
)
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
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MongoDB 不关心地理空间“字段”的键。它只需要前两个元素,第一个元素是经度,第二个元素是纬度。即使您将第一个名称命名为“lat”,它仍然会被视为经度。我认为它不会插入的唯一原因可能是您在某些字段上有一个唯一的键。
如果您添加要插入的内容的完整工作(但很小)示例,那么我可以更新答案以希望显示出问题所在。
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.