Simple Meteor Map for mongo Location Data

I want to create an admin form for my meteor application; I was going to try Ogno Admin before starting to create one from scratch, but I'm not sure if it supports the data in the format I need. My current app data goes to mongo as follows:

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"
        },

Can I write a simple diagram to support the various arrays / objects above (e.g. location coordinates)? Should they be square brackets in the format [lng, lat] - and will the ogno administrator work with this, or will I have to write custom materials? It might be easier for me to create an admin site elsewhere and get it to output JSON data for Meteor.

Update with possible schema code

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!
  */
  ...
});
+4
3

, . lng lat, . ? . -90 90 -180 180. , , ? , - , - , .

:

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

. GeocoordsSchema LocationSchema .

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

LocationSchema, [].

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

, , . , lat lng. ?

+10

chaosbohne, , :

SimpleSchema.messages
  lonOutOfRange: '[label] longitude should be between -90 and 90'
  latOutOfRange: '[label] latitude should be between -180 and 180'

LocationSchema = new SimpleSchema
  type:
    type: String,
    allowedValues: ['Point']
  coordinates:
    type: [Number]
    decimal: true
    minCount: 2
    maxCount: 2
    custom: ->
      return "lonOutOfRange" unless -90 <= @value[0] <= 90
      return "latOutOfRange" unless -180 < @value[1] <= 180

SimpleSchema. minCount maxCount, . - :

SimpleSchema.messages
  needsLatLong: '[label] should be of form [longitude, latitude]'
  lonOutOfRange: '[label] longitude should be between -90 and 90'
  latOutOfRange: '[label] latitude should be between -180 and 180'

LocationSchema = new SimpleSchema
  type:
    type: String,
    allowedValues: ['Point']
  coordinates:
    type: [Number]
    decimal: true
    custom: ->
      return "needsLatLong" unless @value.length is 2
      return "lonOutOfRange" unless -90 <= @value[0] <= 90
      return "latOutOfRange" unless -180 < @value[1] <= 180

:

Beaches = new SimpleSchema
  name:
    type: String
  location:
    type: LocationSchema
    index: '2dsphere'
  images:
    type: [Object]
  "images.$.url":
    type: String
  "images.$.caption":
    type: String
  attributes:
    type: [Object]

index: '2dsphere', MongoDB .

+6

OP, , , , StackOverflow.

, PlaceSchema :

LocationSchema = new SimpleSchema({
    "type":{
        type: String,
        allowedValues: ["Point"]
    },
    "coordinates":{
        type: Array,
        minCount: 2,
        maxCount: 2
    },
    "coordinates.$":{
        type: Number,
        decimal: true,
        custom: function(){
            if(!(-90 <= this.value[0] <= 90))
                return "lonOutOfRange" ;
            if(!(-180 <= this.value[1] <= 180))
                return "latOutOfRange" ;
        }

    },
    "name": {
        type: String,
        optional: true
    },
});



LocationSchema.messages = {
  lonOutOfRange: 'Longitude out of range', // Must be between -90 and 90
  latOutOfRange: 'Latitude out of range' // Must be between -180 and 180
}

:

BeachSchema = new SimpleSchema({
    name: {
        type: String,
    },
    location: {
        type: LocationSchema // HERE
    }
    // ...
});

Then attach the circuit to your collection:

Beaches.attachSchema(BeachSchema);//*/

You can also add an index 2dsphere:

Beaches._ensureIndex({ "location": "2dsphere"});
+2
source

Source: https://habr.com/ru/post/1546571/


All Articles