private static List<Bson> getServerQuery(Bson filter) { final List<Bson> pipeline = new ArrayList<>(6); if (filter != ALL) { pipeline.add(Aggregates.match(filter)); } pipeline.add(Aggregates.unwind("$deployments", new UnwindOptions().preserveNullAndEmptyArrays(true))); pipeline.add(Aggregates.lookup(Collections.APPLICATIONS, "deployments.applicationId", "id", "applications")); pipeline.add(Aggregates.unwind("$applications", new UnwindOptions().preserveNullAndEmptyArrays(true))); pipeline.add(Aggregates.group( new Document().append("hostname", "$hostname").append("environment", "$environment"), new BsonField("fqdn", new Document("$first", "$fqdn")), new BsonField("description", new Document("$first", "$description")), new BsonField("os", new Document("$first", "$os")), new BsonField("network", new Document("$first", "$network")), new BsonField("meta", new Document("$first", "$meta")), new BsonField("attributes", new Document("$first", "$attributes")), new BsonField("applications", new Document("$push", "$applications")), new BsonField("deployments", new Document("$push", "$deployments")))); pipeline.add(Aggregates.sort(Sorts.ascending("_id"))); return pipeline; }
/** * Add a $group step to filter out redundant solutions. * @return True if the distinct operation was successfully appended. */ public boolean distinct() { List<String> key = new LinkedList<>(); for (String varName : bindingNames) { key.add(hashFieldExpr(varName)); } List<BsonField> reduceOps = new LinkedList<>(); for (String field : FIELDS) { reduceOps.add(new BsonField(field, new Document("$first", "$" + field))); } pipeline.add(Aggregates.group(new Document("$concat", key), reduceOps)); return true; }
public List<BsonField> getAccumulators() { return accumulators; }
public MongoAccumulator setAccumulators(List<BsonField> accumulators) { this.accumulators = accumulators; return this; }