-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Serialization
-
Labels:None
if you have an object with a field of
public GeoJsonFeature<GeoJson2DGeographicCoordinates> Features { get; set; }
and you try to index on it, mongod requires the index to be on "Features.Geometry" but when you try to create an index definition on "Features.Geometry"
await Geography.Indexes.CreateManyAsync(new List<CreateIndexModel<GeoEntity>> { new CreateIndexModel<GeoEntity>(Builders<GeoEntity>.IndexKeys.Geo2DSphere(x => x.Features.Geometry)) });
The driver throws an exception with a message that it can't determine serialization info for "Features.Geometry", if you try to create the index on just "Features", mongod blows up. if you manually create the index, like:
await Geography.Indexes.CreateManyAsync(new List<CreateIndexModel<GeoEntity>> { new CreateIndexModel<GeoEntity>(Builders<GeoEntity>.IndexKeys.Geo2DSphere("features.geometry")) });
It creates the Index OK.
If you now try to query, like
await Database.Geography.Find(Builders<GeoEntity>.Filter.NearSphere(x => x.Features.Geometry, location.Longitude, location.Latitude, 1600, 0)).ToListAsync();
it blows up, again unable to determine serialization information for "Features.Geometry"
but this query works just fine
var query = new BsonDocument("features.geometry", new BsonDocument("$geoNear", new BsonDocument("$geometry", new BsonDocument("type", "Point") .Add("coordinates", new BsonArray {location.Longitude, location.Latitude})).Add("$minDistance", 0).Add("$maxDistance", 1600))); var possibleStates = await Database.Geography.Find(query).ToListAsync();