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

IFindFluent.Projection fails with ExpressionNotSupportedException after upgrading to 2.19.0

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      I've always relied on the driver's projection functionality using LINQ expressions. Before version 2.19.0, it worked well, selecting only those fields, that were used in the projection expression, translating known functions into the mongo functions, and doing client-side projections for the functions that were unable to be translated.

      But now, in 2.19.0, I can no longer use functions that I want to run client-side. Let's say I have a BsonDocument collection and want to select only 2 fields, then I want to do a client-side projection using those 2 fields and my custom function. I used to just write:

      var find =
          mongoCollection
              .Find(document => true)
              .Project(document => Functions.MyClientSideProjectionFunction(document["_key"], document["prop"])); 

      and it used to work well, but now, it fails with this error: 

      MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: MyClientSideProjectionFunction(document.get_Item("_key"), document.get_Item("prop")). 

      You can't even make a tuple with those selected properties to map them later. ValueTuple.Create and Tuple.Create functions also fail.

      This happens at the library level, so it doesn't matter which server configuration you use.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            gdar91@live.com GDar N/A
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: