mongodb - How to do geo searches on two properties as opposed to an array of [ lng, lat ]? -


All examples and the implementation of geographic discovery in Mongo, which I am able to find, use an array property <

  {name: 'foo bar', locations:  [[Name: 'Franks House', Geo: [-0.12, 34.51]}, {Name: 'Jennifer's House', Geo : [-0.09, 32.17]}]}  

and the resulting query:

  db.events.find ({'places.geo': { Sphere near $: [-0.12, 34.51], $ maxDistance: 0.02}})  

This works fine, but the user is required to read or write The draft format is not good because it is not the document itself where go to lat and lng that's the room for passches in that array. I want to make the record more human friend:

  {name: 'foo bar', locations: [{Name: 'Friends House', Latitude: 34.51, LNG: -0.12}, {Name: 'jennifers house', lat: 32.17 , Lng: -0.09}]}  

What kind of demand query does this type of record look for? I am unable to find any examples about this, so I am thinking that this is also possible.

It is not recommended to use different areas for latitude and longitude of the 2dsphere index Used for geological data index, for which an array of coordinates is required, see. This is the reason why you can not get examples of different coordinate areas.

You should separate representations from data collection. Just because the coordinates are stored in an array, you do not necessarily have to present them as an array for the user. For example, you can use a pre-call to save different parameters in an array, such as something:

  var schema = new schema (..); Schema.pre ('save', function (next) {this.coordinates = [this.longitude, this.latitude] next ();});  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -