Howto Use SimpleSchema to fill GeoData in Database?


Hi there,

I am having troubles using SimpleSchema to define a location object and fill in gMaps event data (event.latLng , or )
Also I want to use MongoDbs near function to search the data.

similar to

Does anyone have a working snippet of this task?
Thanks a lot


I do it with the following code:
Places = new SimpleSchema({
‘loc’ : {
type: [Number],
decimal: true,
index: “2dsphere”,
optional: false,
label : “Long/Lat Coords”,
minCount: 2,
maxCount: 2

Dont forget to create an 2dsphere index in your MongoDb collection.


I’m using this one:

location: {
    type: Object,
    index: '2dsphere',
    label: 'MongoDB spesific coordinates field'
'location.type': {
    type: String,
    allowedValues: ['Point'],
    label: 'Typeof coordinates - Point'
'location.coordinates': {
    type: [Number],
    decimal: true,
    label: 'Array of coordinates in MongoDB style \[Lng, Lat\]'


Thanks guys!

How would you in both cases set the values from a command like

Markers.insert({ user: Session.get(‘user’), loc.???:});

event.latLng is what I get from the mapClickEvent (gmaps v3).
My meteor does not even compile when I do something like loc. (no extension allowed). So I must pass a complete object and in the correct order (long/lat for mongo).


Maybe smth like this:

  Markers.insert({ user: Session.get('user'), location: {"type": "Point", "coordinates": [event.latLng.lng(),]}});


Great! Works out of the box. Thanks heaps!