问题描述
似乎Sailsjs / Waterline目前不支持使用JSON的POINT类型或地理空间索引。
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?
如果没有,是有没有办法将第二个ORM集成到Waterline中呢?
If not, is there a way to integrate a second ORM into Waterline that does so?
推荐答案
在Sails.js中,你需要MongoDB(npm install --save sails-mongo)用于地理空间索引,另外你需要确保在config / bootstrap.js中创建2dindex(确保根据你的特定需求替换modelname和attributename):
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();
});
});
};
另请注意,您必须使用本机MongoDB地理空间查询,这超出了您的问题的范围。我已经发布了一个示例实现
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
这篇关于Sailsjs地理空间解决方案与水线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!