如何在mongoDB中存储地理空间信息 [英] How to store geospatial information in mongoDB

查看:139
本文介绍了如何在mongoDB中存储地理空间信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据mongoDB文档 (链接) 如果要在文档字段中存储地理空间信息,则有两个选项,一个数组或一个嵌入式文档,并且顺序应始终为经度,纬度.

Acording to the mongoDB documentation (link) if you want to store geospatial information in a document field, you have two options, an array or an embedded document, and the order should be always longitude, latitude.

如果要使用嵌入式文档,如何确保字段的顺序?

If I want to use an embedded document, how can I ensure the field's order?

还是嵌入式文档中的字段必须具有特定名称?

Or must the fields in the embedded document have a specific name?

推荐答案

对于嵌入式文档,无论嵌入式文档中字段的名称如何,第一个字段应包含经度值,第二个字段应包含纬度价值.例如:

with an embedded document, regardless of the name of the field in the embedded document, the first field should contain the longitude value and the second field should contain the latitude value. For example:

 db.zips2.insert( { _id: 1, city: "b", loc: { x: -73.974, y: 40.764 } } )
 db.zips2.insert( { _id: 2, city: "b", loc: { x: -73.981, y: 40.768 } } )

此处 x 字段为经度;并且 y 字段为纬度.

Here the x field would be the longitude; and the y field would be the latitude.

致谢

这篇关于如何在mongoDB中存储地理空间信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆