Sailsjs/Waterline目前似乎不支持JSON的点类型或地理空间索引。
有没有办法为某些适配器定制模式以支持地理空间数据类型?
如果没有,有没有办法将第二个ORM集成到Waterline中?
发布于 2016-01-31 06:32:34
在Sails.js中,您需要MongoDB (npm install --save sails-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
发布于 2014-01-09 19:56:27
如果您查看waterline文档,您可以了解如何创建自定义数据类型和您自己的验证,您可以找到地理空间示例here
https://stackoverflow.com/questions/21005125
复制相似问题