7

It seems like Sailsjs/Waterline does not currently support a POINT type or geospatial indexing with JSON.

Are there any ways to customize a schema for certain adapters to support geospatial datatypes?

If not, is there a way to integrate a second ORM into Waterline that does so?

Joe Hill
  • 333
  • 3
  • 12
gtg092x
  • 171
  • 2

2 Answers2

1

In Sails.js, you need MongoDB (npm install --save sails-mongo) for geospatial indexing, plus you need to ensure the 2dindex gets created in config/bootstrap.js as such (make sure to replace modelname and attributename for your particular needs):

module.exports.bootstrap = function(cb) {

  // Ensure we have 2dsphere index on coordinates attribute of Place.
  sails.models.modelname.native(function (err, collection) {
    collection.ensureIndex({ attributename: '2dsphere' }, function () {

    // It's very important to trigger this callback method when you are finished
    // with the bootstrap!  (otherwise your server will never lift, since it's waiting on the bootstrap)
    cb();

    });
  });

};

Also note that you have to use native MongoDB geospatial queries, which is beyond the scope of your question. I've posted an example implementation here

0

If you check the waterline documentation you can see how to create custom data types and your own validation, you can find a geospatial example here

omarayad1
  • 34
  • 2
  • 1
    Not helpful, that example doesn't show how to do anything other than create a point. This requires .Native mongodb or a haversine formula implementation – Zach Leighton Feb 12 '15 at 21:00
  • Your link is out of date. Anyone looking for how to create custom data types: take at look here: https://github.com/balderdashy/waterline/blob/4744f1edbba27921a8fea588393facc8382e4d96/README.md#custom-types – qualbeen Nov 16 '16 at 18:42