【发布时间】:2014-01-08 19:47:05
【问题描述】:
目前看来 Sailsjs/Waterline 不支持 POINT 类型或使用 JSON 的地理空间索引。
是否有任何方法可以为某些适配器自定义架构以支持地理空间数据类型?
如果没有,有没有办法将第二个 ORM 集成到 Waterline 中?
【问题讨论】:
标签: javascript sails.js geospatial waterline
目前看来 Sailsjs/Waterline 不支持 POINT 类型或使用 JSON 的地理空间索引。
是否有任何方法可以为某些适配器自定义架构以支持地理空间数据类型?
如果没有,有没有办法将第二个 ORM 集成到 Waterline 中?
【问题讨论】:
标签: javascript sails.js geospatial waterline
在 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
【讨论】:
如果您查看水线文档,您可以了解如何创建自定义数据类型和您自己的验证,您可以找到地理空间示例 here
【讨论】: