I want to compute a new field using project stage in aggregation pipeline in Java driver. I want create new field by just multiplying value (that is coming from previous stages) with 100.
Bson projectGroup= Aggregates.project(
Projections.fields(
Projections.computed("computed", "{'$multiply':[100,'value']}}}")
)
);
Result has the computed field but its value is static expression
""{'$multiply':[100,'value']}}}""
How to get run the expression and get the value.
Answering my own question for others. We need to parse the expression as follows
Bson projectGroup= Aggregates.project(
Projections.fields(
Projections.computed("computed", Document.parse("{'$multiply':[100,'value']}}}"))
)
);