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

Using GeoJson2DCoordinates in a LINQ projection causes a System.NotSupportedException

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 2.20.0
    • Component/s: None
    • Labels:

      Summary

      Using MongoDB.Driver.GeoJsonObjectModel.GeoJson2DCoordinates in a LINQ projection causes a System.NotSupportedException.

      This works as expected in version 2.18.0 of the driver but fails in 2.19 and 2.20.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      2.19.0 and 2.20.0.

      How to Reproduce

      See here for a reproduction. 

      Given the following types

       

      public class PlaceEntity
      {
          public string? Name { get; set; }
          public GeoJson2DCoordinates? Location { get; set; }
      }
      
      public class PlaceHeader
      {
          public string? Name { get; set; }
          public double? Latitude { get; set; }
          public double? Longitude { get; set; }
      } 

      and the following code

       

       

       

      private readonly IMongoCollection<PlaceEntity> _places;
      public async Task<List<PlaceEntity>> GetPlaceEntities()
      {
          return await _places.Find(Builders<PlaceEntity>.Filter.Empty).ToListAsync();
      }
      public async Task<List<PlaceHeader>> GetPlaceHeaders()
      {
          return await _places
              .Find(Builders<PlaceEntity>.Filter.Empty)
              .Project(x => new PlaceHeader
              {
                  Name = x.Name,
                  Latitude = x.Location != null ? x.Location.X : null,
                  Longitude = x.Location != null ? x.Location.Y : null,
              })
              .ToListAsync();
      }
      

      calling GetPlaceEntities() works, but calling GetPlaceHeaders() causes the following exception:

      System.NotSupportedException: Serializer for MongoDB.Driver.GeoJsonObjectModel.GeoJson2DCoordinates must implement IBsonDocumentSerializer to be used with LINQ.

      Is it expected that the GeoJson types can't be used in LINQ projections when using the V3 LINQ provider? These projections work as expected with the V2 provider.

       

       

            Assignee:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            david.wolsey@gmail.com David Wolsey
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: