7

Sailsjs/Waterline 目前似乎不支持 POINT 类型或使用 JSON 的地理空间索引。

是否有任何方法可以为某些适配器自定义模式以支持地理空间数据类型?

如果没有,有没有办法将第二个 ORM 集成到 Waterline 中?

4

2 回答 2

1

在 Sails.js 中,您需要 MongoDB (npm install --savesails-mongo) 用于地理空间索引,此外,您需要确保在 config/bootstrap.js 中创建 2dindex(确保为您的特定替换模型名和属性名)需求):

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();

    });
  });

};

另请注意,您必须使用本机 MongoDB 地理空间查询,这超出了您的问题范围。我在这里发布了一个示例实现

于 2016-01-30T22:32:33.660 回答
0

如果您查看水线文档,您可以了解如何创建自定义数据类型和您自己的验证,您可以在此处找到地理空间示例

于 2014-01-09T11:56:26.807 回答