use of dev.morphia.aggregation.experimental.stages.Stage in project morphia by mongodb.
the class PipelineUpdate method toDocument.
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<Document> toDocument() {
CodecRegistry registry = datastore.getCodecRegistry();
List<Document> documents = new ArrayList<>();
for (Stage update : updates) {
DocumentWriter writer = new DocumentWriter(datastore.getMapper());
Codec codec = registry.get(update.getClass());
codec.encode(writer, update, EncoderContext.builder().build());
documents.add(writer.getDocument());
}
return documents;
}
use of dev.morphia.aggregation.experimental.stages.Stage in project morphia by mongodb.
the class LookupCodec method encodeStage.
@SuppressWarnings("unchecked")
@Override
protected void encodeStage(BsonWriter writer, Lookup value, EncoderContext encoderContext) {
document(writer, () -> {
if (value.getFrom() != null) {
writer.writeString("from", value.getFrom());
} else {
writer.writeString("from", getDatastore().getMapper().getEntityModel(value.getFromType()).getCollectionName());
}
List<Stage> pipeline = value.getPipeline();
if (pipeline == null) {
writer.writeString("localField", value.getLocalField());
writer.writeString("foreignField", value.getForeignField());
} else {
ExpressionHelper.expression(getDatastore(), writer, "let", value.getVariables(), encoderContext);
array(writer, "pipeline", () -> {
for (Stage stage : pipeline) {
Codec<Stage> codec = (Codec<Stage>) getCodecRegistry().get(stage.getClass());
codec.encode(writer, stage, encoderContext);
}
});
}
writer.writeString("as", value.getAs());
});
}
use of dev.morphia.aggregation.experimental.stages.Stage in project morphia by mongodb.
the class FacetCodec method encodeStage.
@Override
protected void encodeStage(BsonWriter writer, Facet value, EncoderContext encoderContext) {
document(writer, () -> {
for (Entry<String, List<Stage>> entry : value.getFields().entrySet()) {
array(writer, entry.getKey(), () -> {
List<Stage> stages = entry.getValue();
for (Stage stage : stages) {
Codec codec = getCodecRegistry().get(stage.getClass());
codec.encode(writer, stage, encoderContext);
}
});
}
});
}
Aggregations