I have a Number data type in the schema (simple-schema) but am unable to store floating point numbers in it when using collections2:
Schema.Coordinates = new SimpleSchema({
lng: {
type: Number,
min: -180.0,
max: 180.0
},
lat: {
type: Number,
min: -90.0,
max: 90.0
}
});
When I try to insert anything other than an integer (anything with xxxx.0) I get a validation error:
W20150222-20:24:23.523(-8)? (STDERR) Error: Lng must be an integer
As has already been stated, setting decimal to true will allow for floating point numbers.
I just wanted to make another suggestion. Since you're trying to store log/lat this would be a better schema:
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
That allows you to store the coordinates in GeoJSON format so that you can then use Mongo's spacial operators (such as $near) on the server.
You can set decimal to true (docs). I guess this is a bit like optional else like the other answer.
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,
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With