1

I have been using sails.js on a project which will show posts near a users location, however while I have had no trouble in finding references and tools to geocode an address I cannot find any information on finding these by distance from another set of coordinates, the way you would using regular mongodb. my places model is:

module.exports = {
    attributes: {
        longitude: {
            type: 'float',
            required: true
        },
        latitude: {
            type: 'float'
        },
        country: {
            type: 'string'
        },
        city: {
            type: 'string'
        },
        stateCode: {
            type: 'string'
        },
        zipcode: {
            type: 'string'
        },
        streetName: {
            type: 'string'
        },
        streetNumber: {
            type: 'string'
        }
    }
};

How would i compose a find of this model in order to find and sort by distance within a set range?

james0
  • 55
  • 1
  • 9

1 Answers1

1

sails-mongo does not support the use of $near, however if you ensure your model is set up as follows you can use the .native function:

attributes: {
location: {
    index: '2d',
    longitude: {
        type: 'float',
        required: true,
    },
    latitude: {
        type: 'float',
    }
},
...

see this post for more information: https://github.com/balderdashy/sails-mongo/issues/46

james0
  • 55
  • 1
  • 9