Considering this class:
public class Location
{
public Coordinates Geo { get; set; }
public Location()
{
Geo = new Coordinates();
}
public class Coordinates
{
public decimal Lat { get; set; }
public decimal Long { get; set; }
}
}
I have a geospatial index on the collection set like { Geo: "2d" }
. Unfortunately the driver tries to store lat/lon coordinates as strings, instead of numbers and I get an error that says Tue Mar 15 16:29:22 [conn8] insert database.locations exception 13026 geo values have to be numbers: { Lat: "50.0853779", Long: "19.931276700000012" } 1ms. To alleviate this problem I setup a map like this:
BsonClassMap.RegisterClassMap<Location.Coordinates>(cm =>
{
cm.AutoMap();
cm.MapProperty(c => c.Lat).SetRepresentation(BsonType.Double);
cm.MapProperty(c => c.Long).SetRepresentation(BsonType.Double);
});
Notice that there is no BsonType.Decimal
nor anything like that. In the effect, when trying to call Save()
I get a MongoDB.Bson.TruncationException
, which seems logical. What are my options?