【问题标题】:Sailsjs Geospatial Solution with WaterlineSailsjs 带水线的地理空间解决方案
【发布时间】:2014-01-08 19:47:05
【问题描述】:

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

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

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

【问题讨论】:

    标签: javascript sails.js geospatial waterline


    【解决方案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 地理空间查询,这超出了您的问题范围。我已经发布了一个示例实现here

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 没有帮助,该示例没有显示除了创建点之外如何做任何事情。这需要 .Native mongodb 或 hasrsine 公式实现
      • 您的链接已过期。任何寻找如何创建自定义数据类型的人:看这里:github.com/balderdashy/waterline/blob/…
      猜你喜欢
      • 2021-02-08
      • 1970-01-01
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      相关资源
      最近更新 更多