Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2038

Can't Query/Index GeoJson Using Typed fields

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Serialization
    • Labels:
      None

      Description

      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();
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            peter.garafano Peter Garafano
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: