Given 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 in a collection set like { Geo: "2d" } . Unfortunately, the driver tries to save the lat / lon coordinates as strings, not numbers, and I get an error message that says Tue Mar 15 16:29:22 [conn8] insert database.locations exception 13026 geo values โโmust be numbers : {Lat: "50.0853779", long: "19.931276700000012"} 1 ms. To fix this problem, I configure this card:
BsonClassMap.RegisterClassMap<Location.Coordinates>(cm => { cm.AutoMap(); cm.MapProperty(c => c.Lat).SetRepresentation(BsonType.Double); cm.MapProperty(c => c.Long).SetRepresentation(BsonType.Double); });
Note that there is no BsonType.Decimal and nothing like that. As a result, when I try to call Save() I get a MongoDB.Bson.TruncationException , which seems logical. What are my options?
source share