Search in sources :

Example 1 with Sort

use of dev.morphia.query.Sort in project morphia by mongodb.

the class AggregationPipelineImpl method sort.

@Override
public AggregationPipeline sort(Sort... sorts) {
    Document sortList = new Document();
    for (Sort sort : sorts) {
        sortList.put(sort.getField(), sort.getOrder());
    }
    stages.add(new Document("$sort", sortList));
    return this;
}
Also used : Sort(dev.morphia.query.Sort) Document(org.bson.Document)

Example 2 with Sort

use of dev.morphia.query.Sort in project morphia by mongodb.

the class SetWindowFieldsCodec method encodeStage.

@Override
protected void encodeStage(BsonWriter writer, SetWindowFields value, EncoderContext encoderContext) {
    document(writer, () -> {
        if (value.partition() != null) {
            writer.writeName("partitionBy");
            expression(getDatastore(), writer, value.partition(), encoderContext);
        }
        Sort[] sorts = value.sorts();
        if (sorts != null) {
            document(writer, "sortBy", () -> {
                for (Sort sort : sorts) {
                    writer.writeInt64(sort.getField(), sort.getOrder());
                }
            });
        }
        document(writer, "output", () -> {
            for (Output output : value.outputs()) {
                document(writer, output.name(), () -> {
                    operator(writer, encoderContext, output.operator());
                    window(writer, output, encoderContext);
                });
            }
        });
    });
}
Also used : Output(dev.morphia.aggregation.experimental.stages.SetWindowFields.Output) Sort(dev.morphia.query.Sort)

Aggregations

Sort (dev.morphia.query.Sort)2 Output (dev.morphia.aggregation.experimental.stages.SetWindowFields.Output)1 Document (org.bson.Document)1