Package org.restheart.mongodb.utils
Class VarsInterpolator
java.lang.Object
org.restheart.mongodb.utils.VarsInterpolator
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.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.bson.BsonValueinterpolate(VarsInterpolator.VAR_OPERATOR operator, org.bson.BsonValue bson, org.bson.BsonDocument values)
-
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 variablesvalues- 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: ifbson = {"$var": "name" }andavars = { "name": "Andrea"}then it returns{"$var": "Andrea" } - Throws:
InvalidMetadataExceptionQueryVariableNotBoundException
-