2015-02-23 57 views
2

我在模式(简单模式)数字数据类型,但我无法储存使用collections2当浮点数是:如何使用Collections2在Meteor(JS)中存储浮点值?

Schema.Coordinates = new SimpleSchema({ lng: { type: Number, min: -180.0, max: 180.0 }, lat: { type: Number, min: -90.0, max: 90.0 } });

当我尝试插入其他任何东西比一个整数(与xxxx.0任何东西),我得到验证错误:

W20150222-20:24:23.523(-8)? (STDERR) Error: Lng must be an integer

回答

2

您可以设置decimal为true(docs)。我想这有点像可选其他类似于其他答案。

Schema.Coordinates = new SimpleSchema({ 
    lng: { 
     type: Number, 
     min: -180.0, 
     max: 180.0, 
     decimal:true, 
    }, 
    lat: { 
     type: Number, 
     min: -90.0, 
     max: 90.0, 
     decimal: true, 
    } 
}); 
4

如前所述,将decimal设置为true将允许浮点数。

我只是想提出另一个建议。既然你想存储日志/ LAT,这将是一个更好的模式:

loc: 
    type: Object 
    index: '2dsphere' 
    label: "Location" 

"loc.type": 
    type: String 
    allowedValues: [ "Point" ] 
    label: "Start location type" 

"loc.coordinates": 
    type: [Number] 
    minCount: 2 
    maxCount: 2 
    decimal: true 

这可以让你的坐标存储在GeoJSON格式,这样你就可以在使用蒙戈的空间运营商(如$near)服务器。