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

Replace parameter names that aren't valid server variable names with generated variable names

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.15.1
    • Affects Version/s: None
    • Component/s: LINQ3
    • None

      Summary

      When provided an expression that was generated by a tool (such as `Mapster`), the driver appears to alias unnamed parameters with underscores, which results in a mongodb query exception such as `Command aggregate failed: '_p1' starts with an invalid character for a user variable name.`

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

      Driver 2.15.0

      How to Reproduce

      Manually creating an Expression against a `IMongoCollection.AsQueryable()` should result in the error.

      Additional Background

      General usage works (normally `Select(i => new Child { Id = i.Id})` defined lambdas):

       

      .Select(Param_0 => new ItemFacade() {
      	Id = Param_0.Id.ToString()
      	Children = Param_0.Children.Select(i => new ChildFacade() {ChildId = i.ChildId})
      
      { "$map" : { "input" : "$Children", "as" : "i", "in" : { "ChildId" : "$$i.ChildId" } } }
      

       

      But if the expression was generated by a tool that doesn't name parameters, it results in that mongodb error:

       

      .Select(Param_0 => new ItemFacade() {
      	Id = Param_0.Id.ToString(), 
      	Children = Param_0.Children.Select(Param_1 => new ChildFacade() {ChildId = Param_1.ChildId})
      })
      
      { "$map" : { "input" : "$Children", "as" : "_p1", "in" : { "ChildId" : "$$_p1.ChildId" } } }

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            jayoungers@gmail.com John Youngers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: