Search in sources :

Example 1 with Expression

use of dev.morphia.aggregation.experimental.expressions.impls.Expression in project morphia by mongodb.

the class Filters method expr.

/**
 * Allows use of aggregation expressions within the query language.
 *
 * @param expression the expression to evaluate
 * @return the filter
 * @query.filter $expr
 */
public static Filter expr(Expression expression) {
    return new Filter("$expr", null, expression) {

        @Override
        public void encode(Datastore datastore, BsonWriter writer, EncoderContext context) {
            writer.writeName("$expr");
            Expression value = getValue();
            if (value != null) {
                wrapExpression(datastore, writer, value, context);
            } else {
                writer.writeNull();
            }
        }

        @Override
        public Expression getValue() {
            return (Expression) super.getValue();
        }
    };
}
Also used : Datastore(dev.morphia.Datastore) EncoderContext(org.bson.codecs.EncoderContext) Expression(dev.morphia.aggregation.experimental.expressions.impls.Expression) ExpressionHelper.wrapExpression(dev.morphia.aggregation.experimental.codecs.ExpressionHelper.wrapExpression) BsonWriter(org.bson.BsonWriter)

Aggregations

Datastore (dev.morphia.Datastore)1 ExpressionHelper.wrapExpression (dev.morphia.aggregation.experimental.codecs.ExpressionHelper.wrapExpression)1 Expression (dev.morphia.aggregation.experimental.expressions.impls.Expression)1 BsonWriter (org.bson.BsonWriter)1 EncoderContext (org.bson.codecs.EncoderContext)1