Class VarsInterpolator

java.lang.Object
org.restheart.mongodb.utils.VarsInterpolator

public class VarsInterpolator extends Object
Utility class for interpolating variables within a BsonDocument or BsonArray by using a specific format, such as { [operator]: "name"}, and replacing placeholders with provided values. The class facilitates the dynamic substitution of placeholders in BSON documents and arrays.
  • Constructor Details

    • VarsInterpolator

      public VarsInterpolator()
  • Method Details

    • interpolate

      public static org.bson.BsonValue interpolate(VarsInterpolator.VAR_OPERATOR operator, org.bson.BsonValue bson, org.bson.BsonDocument values) throws InvalidMetadataException, QueryVariableNotBoundException
      Parameters:
      operator -
      bson - the BsonDocument or BsonArray containing variables
      values - the BsonDocument containing the values of the variables, as RequestContext.getAggregationVars()
      Returns:
      the BsonValue where the variables {"$var": "name" } or {"$var": [ "name", "defaultValue" ] } are replaced with the values defined in the avars BsonDocument

      Example: if bson = {"$var": "name" } and avars = { "name": "Andrea"} then it returns {"$var": "Andrea" }
      Throws:
      InvalidMetadataException
      QueryVariableNotBoundException