spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Add a generic PropertyExpression for AggregationExpression

Open haiderali22 opened this issue 2 years ago • 2 comments

Add a generic PropertyExpression to give an alias for any AggregationExpression currently you can use a class in ArrayOperators.Reduce.PropertyExpression which is i think misleading as i first thought it will be only used in related to ArrayOperators.Reduce

haiderali22 avatar Jul 11 '23 11:07 haiderali22

Let's take a step back before trying to fix an issue and elaborate on what you want to achieve.

mp911de avatar Jul 17 '23 14:07 mp911de

@mp911de for the following mongodb stage

{ 
  $addFields: { 
    orders:{ 
      $map: {
          input: "$orders", 
          as: "order", 
          in: { 
              $mergeObjects: [ 
                "$$order", 
              { 
                **instance:** { 
                  $first: { 
                      $filter: { 
                      input: "$instances", 
                      as: "instance", 
                      cond: { 
                        $eq: [ "$$order.instance.docKey", "$$instance._id", 
                         ], 
                      }, 
                        
                      }, 
                      
                    }
                },
              }, 
              ],
            }, 
        }, 
    }, 
 }
}

to give alias (instance) for result of $first(aggregate expression) i have used ```

ArrayOperators.Reduce.PropertyExpression.property("instance")
.definedAs(aggregateExpression) 

so what i said is PropertyExpression should be in separate class instead of in ArrayOperators.Reduce

haiderali22 avatar Jul 17 '23 16:07 haiderali22