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 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); }
/** * @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; }
@Override public Document toDocument(AggregationOperationContext context) { Document document = new Document(); document.put("input", getMappedValue(input, context)); document.put("initialValue", getMappedValue(initialValue, context)); if (reduceExpressions.iterator().next() instanceof PropertyExpression) { Document properties = new Document(); for (AggregationExpression e : reduceExpressions) { properties.putAll(e.toDocument(context)); } document.put("in", properties); } else { document.put("in", (reduceExpressions.iterator().next()).toDocument(context)); } return new Document("$reduce", document); }
/** * 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); }
public Document getFieldsObject() { @SuppressWarnings({ "unchecked", "rawtypes" }) Document document = new Document((Map) criteria); for (Entry<String, Object> entry : slices.entrySet()) { document.put(entry.getKey(), new Document("$slice", entry.getValue())); } for (Entry<String, Criteria> entry : elemMatchs.entrySet()) { document.put(entry.getKey(), new Document("$elemMatch", entry.getValue().getCriteriaObject())); } if (positionKey != null) { document.put(positionKey + ".$", positionValue); } 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); }
private Document toMap(ExposedFields exposedFields, AggregationOperationContext context) { Document map = new Document(); InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext( exposedFields, context); Document input; if (sourceArray instanceof Field) { input = new Document("input", context.getReference((Field) sourceArray).toString()); } else { input = new Document("input", ((AggregationExpression) sourceArray).toDocument(context)); } map.putAll(context.getMappedObject(input)); map.put("as", itemVariableName); map.put("in", functionToApply.toDocument(new NestedDelegatingExpressionAggregationOperationContext(operationContext))); return new Document("$map", map); }
@Override public Document toDocument(AggregationOperationContext context) { Document dbo = new Document("case", when.toDocument(context)); if (then instanceof AggregationExpression) { dbo.put("then", ((AggregationExpression) then).toDocument(context)); } else if (then instanceof Field) { dbo.put("then", context.getReference((Field) then).toString()); } else { dbo.put("then", then); } return dbo; }
private Document updateTypeRestrictions(Document query, Example example) { Document result = new Document(); if (isTypeRestricting(example)) { result.putAll(query); this.converter.getTypeMapper().writeTypeRestrictions(result, getTypesToMatch(example)); return result; } for (Map.Entry<String, Object> entry : query.entrySet()) { if (!this.converter.getTypeMapper().isTypeKey(entry.getKey())) { result.put(entry.getKey(), entry.getValue()); } } return result; }
@Override public Document toDocument(AggregationOperationContext context) { String path = context.getReference(field).toString(); if (!preserveNullAndEmptyArrays && arrayIndex == null) { return new Document("$unwind", path); } Document unwindArgs = new Document(); unwindArgs.put("path", path); if (arrayIndex != null) { unwindArgs.put("includeArrayIndex", arrayIndex.getName()); } unwindArgs.put("preserveNullAndEmptyArrays", preserveNullAndEmptyArrays); return new Document("$unwind", unwindArgs); }
private Document convertArrays(Document doc) { Document retVal = new Document(); for (Map.Entry<String, Object> entry : doc.entrySet()) { if (entry.getValue() != null && entry.getValue().getClass().isArray()) { retVal.put(entry.getKey(), convertArrays((Object[])entry.getValue())); } else if (entry.getValue() != null && (entry.getValue() instanceof Map || entry.getValue() instanceof Document)) { retVal.put(entry.getKey(), convertArrays(new Document((Map)entry.getValue()))); } else { retVal.put(entry.getKey(), entry.getValue()); } } return retVal; }