mongo地理位置数据的流星简单方案 [英] Meteor simple schema for mongo geo location data

查看:72
本文介绍了mongo地理位置数据的流星简单方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的流星应用程序创建一个管理表单;我打算先尝试使用Ogno Admin,然后再从头开始构建一个,但是我不确定它是否可以支持所需格式的数据.我当前的应用数据会像这样进入mongo:

I want to create an admin form for my meteor app; I was going to try Ogno Admin before resorting to building one from scratch but I'm not sure if it can support the data in the format that I need. My current app data goes into mongo like this:

Beaches.insert({
    "name": "Entry name",
    /* location stored like this so I can use mongo $near queries */
    "location": {
        "type": "Point",
        "coordinates": [-5.0990296,50.110757]
    },
    /* could be many images, minimum 1 */
    "images": [
        {
            "url": "image1.jpg",
            "caption": "Image caption"
        }
    ],
    "shortDesc": "A delightful description...",
    /* fixed list of attributes stored as objects */
    "attributes": {
        "attr 1": {
            "score": 2,
            "text": "attr1 text"
        },

我可以编写一个简单的架构来支持上面的不同数组/对象(尤其是位置坐标)吗?它们必须为方括号格式[lng,lat]-ogno admin可以使用此格式,还是我必须编写自定义admin的东西?对于我来说,在其他地方构建管理站点并获得它来输出Meteor的JSON数据可能更容易.

Could I write a simple schema to support the different arrays/objects above (esp. location coords)? They have to be square bracket formatted [lng, lat] - and would ogno admin work with this, or would I have to write the custom admin stuff? It might be easier for me to build the admin site in something else and get that to output JSON data for Meteor.

Beaches = new SimpleSchema({
  name: {
    type: String,
  },
  location: {
    type: [Object]
  },
    location.$.type: {
    /* how do I force '"type" : "Point" into every entry?
       use 'autovalue' with the .clean() function?*/
    },
      location.$.coordinates: {
      /* how do I ensure a [x,y] array in here? */
    },
  images: {
    type: [Object]
  },
    "images.$.url": {
        type: String
    },
    "images.$.caption": {
        type: String
    },
  attributes: {
    type: [Object]
  },
  /* note that my attributes above are all prefixed with a 'name'
     eg. "attr 1" : {}
     I'm not sure how to declare these either!
  */
  ...
});

推荐答案

嗯,我不完全知道您保存地理坐标的过程的解决方案.但是,如果要保存lng和lat,则必须传递前缀.为什么?良好的地质坐标具有不同的验证范围.纬度仅在-90到90之间可用,而经度在-180到180之间可用.如果不保存前缀,您如何确定哪个坐标?某天我做错的另一个提示是按经纬度顺序存储坐标.

Hmm I dont know exactly the solution to your process of saving geocoords. But if you want to save lng and lat you have to pass a prefix. Why? Well geocoords have different validation ranges. Latitude is only available from -90 to 90 and Longitude from -180 to 180. If you dont save a prefix how do you want to ensure which is which coordinate? Another hint I have done false someday is to store the coords in longitude, latitude order.

我正在使用的架构如下:

The schema I am using looks like this:

GeocoordsSchema = new SimpleSchema({
  lng: {
    type : Number,
    decimal: true,
    min: -180,
    max: 180
  }, 
  lat: {
    type : Number,
    decimal: true,
    min: -90,
    max: 90
  }
});

现在,您将创建嵌套模式.只需使用LocationSchema扩展GeocoordsSchema并添加一个属性即可.

Now you create nested schemas. Just extend GeocoordsSchema with LocationSchema and add a attribute.

LocationSchema = new SimpleSchema({
  type : {
    type : String,
    autoValue: function() {
      return "Point";
    }
  },
  coordinate: {
    type: GeocoordsSchema 
  }
});

如果要使用LocationSchema数组,则可以将模式包装在[]括号中.

If you want to have an array of LocationSchema than you can wrap the schema in [] brackets.

BeachesSchema = new SimpleSchema({
  loc: {
    type: [LocationSchema]
  }
});

我还没有测试过,但这就是我创建和嵌套不同模式的方式.那么这个解决方案需要一个lat和lng的标识符.为什么不想要给数据加上前缀?

I havent tested but thats the way how I create and nest different schemas. Well this solution needs an identifier of lat and lng. Why dont you want to prefix your data?

这篇关于mongo地理位置数据的流星简单方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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