Refine search
@Override public Document toDocument(AggregationOperationContext context) { Document options = new Document(); options.put("buckets", buckets); if (granularity != null) { options.put("granularity", granularity); } options.putAll(super.toDocument(context)); return new Document("$bucketAuto", options); }
private boolean createNearCriteriaForCommand(String command, String operation, double maxDistance) { if (!criteria.containsKey(command)) { return false; } Object existingNearOperationValue = criteria.get(command); if (existingNearOperationValue instanceof Document) { ((Document) existingNearOperationValue).put(operation, maxDistance); return true; } else if (existingNearOperationValue instanceof GeoJson) { Document dbo = new Document("$geometry", existingNearOperationValue).append(operation, maxDistance); criteria.put(command, dbo); return true; } return false; }
/** * Create the JSON schema complying {@link Document} representation. This includes {@literal type}, * {@literal description} and the fields of {@link Restrictions#toDocument()} if set. */ @Override public Document toDocument() { Document document = new Document(); getOrCreateDescription().ifPresent(val -> document.append("description", val)); document.putAll(restrictions.toDocument()); return document; }
private Document toLet(ExposedFields exposedFields, AggregationOperationContext context) { Document letExpression = new Document(); Document mappedVars = new Document(); InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext( exposedFields, context); for (ExpressionVariable var : this.vars) { mappedVars.putAll(getMappedVariable(var, context)); } letExpression.put("vars", mappedVars); letExpression.put("in", getMappedIn(operationContext)); return new Document("$let", letExpression); }
/** * Returns a {@link Document} representation of this {@link AggregationOptions}. * * @return */ public Document toDocument() { Document document = new Document(); document.put(ALLOW_DISK_USE, allowDiskUse); document.put(EXPLAIN, explain); cursor.ifPresent(val -> document.put(CURSOR, val)); collation.ifPresent(val -> document.append(COLLATION, val.toDocument())); return document; }
@Override public Document toDocument(AggregationOperationContext context) { Document options = new Document(); options.put("boundaries", context.getMappedObject(new Document("$set", boundaries)).get("$set")); if (defaultBucket != null) { options.put("default", context.getMappedObject(new Document("$set", defaultBucket)).get("$set")); } options.putAll(super.toDocument(context)); return new Document("$bucket", options); }
/** * Get the {@link Document} representation of the {@link GroupBy}. * * @return */ public Document getGroupByObject() { Document document = new Document(); keys.ifPresent(val -> document.append("key", val)); keyFunction.ifPresent(val -> document.append("$keyf", val)); document.put("$reduce", reduce); document.put("initial", initialDocument); initial.ifPresent(val -> document.append("initial", val)); finalize.ifPresent(val -> document.append("finalize", val)); collation.ifPresent(val -> document.append("collation", val.toDocument())); return document; }
private Document toFilter(ExposedFields exposedFields, AggregationOperationContext context) { Document filterExpression = new Document(); InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext( exposedFields, context); filterExpression.putAll(context.getMappedObject(new Document("input", getMappedInput(context)))); filterExpression.put("as", as.getTarget()); filterExpression.putAll(context.getMappedObject(new Document("cond", getMappedCondition(operationContext)))); return new Document("$filter", filterExpression); }
/** * @return the query {@link Document}. */ public Document getQueryObject() { Document document = new Document(); for (CriteriaDefinition definition : criteria.values()) { document.putAll(definition.getCriteriaObject()); } if (!restrictedTypes.isEmpty()) { document.put(RESTRICTED_TYPES_KEY, getRestrictedTypes()); } return document; }
private Document parseUpdateKey(String updateKey, Map doc) { Document retVal; if (updateKey.equals("_id") && ObjectId.isValid(((String) doc.get(updateKey)))) { retVal = new Document("_id", new ObjectId((String) doc.get(updateKey))); } else if (updateKey.contains(",")) { String[] parts = updateKey.split(",[\\s]*"); retVal = new Document(); for (String part : parts) { retVal.append(part, doc.get(part)); } } else { retVal = new Document(updateKey, doc.get(updateKey)); } return retVal; }