/** * Returns the hint for which index to use. The default is not to set a hint. * * @return the hint * @since 3.6 * @mongodb.server.release 3.6 */ public BsonDocument getHint() { if (hint == null) { return null; } if (!hint.isDocument()) { throw new IllegalArgumentException("Hint is not a BsonDocument please use the #getHintBsonValue() method. "); } return hint.asDocument(); }
AggregateOperationImpl<T> hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
/** * Returns true if the value of the key is a BsonDocument, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonDocument, returns false if the document does not contain the key. */ public boolean isDocument(final Object key) { if (!containsKey(key)) { return false; } return get(key).isDocument(); }
/** * Sets the hint for which index to use. A null value means no hint is set. * * @param hint the hint * @return this * @since 3.6 * @mongodb.server.release 3.6 */ public AggregateExplainOperation hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
/** * Returns the hint for which index to use. The default is not to set a hint. * * @return the hint * @since 3.6 * @mongodb.server.release 3.6 */ public BsonDocument getHint() { BsonValue hint = wrapped.getHint(); if (hint == null) { return null; } if (!hint.isDocument()) { throw new IllegalArgumentException("Hint is not a BsonDocument please use the #getHintBsonValue() method. "); } return hint.asDocument(); }
private void addClause(final BsonDocument document, final Map.Entry<String, BsonValue> clause) { if (clause.getKey().equals("$and")) { for (BsonValue value : clause.getValue().asArray()) { for (Map.Entry<String, BsonValue> element : value.asDocument().entrySet()) { addClause(document, element); } } } else if (document.size() == 1 && document.keySet().iterator().next().equals("$and")) { document.get("$and").asArray().add(new BsonDocument(clause.getKey(), clause.getValue())); } else if (document.containsKey(clause.getKey())) { if (document.get(clause.getKey()).isDocument() && clause.getValue().isDocument()) { BsonDocument existingClauseValue = document.get(clause.getKey()).asDocument(); BsonDocument clauseValue = clause.getValue().asDocument(); if (keysIntersect(clauseValue, existingClauseValue)) { promoteRenderableToDollarForm(document, clause); } else { existingClauseValue.putAll(clauseValue); } } else { promoteRenderableToDollarForm(document, clause); } } else { document.append(clause.getKey(), clause.getValue()); } }
private BsonDocument createFilter(final String fieldName, final BsonValue value) { if (fieldName.startsWith("$")) { return new BsonDocument("$not", new BsonDocument(fieldName, value)); } else if ((value.isDocument() && containsOperator(value.asDocument())) || value.isRegularExpression()) { return new BsonDocument(fieldName, new BsonDocument("$not", value)); } return new BsonDocument(fieldName, new BsonDocument("$not", new BsonDocument("$eq", value))); }
/** * @param responseContent the responseContent to set */ public void setResponseContent(BsonValue responseContent) { if (responseContent != null && !(responseContent.isDocument() || responseContent.isArray())) { throw new IllegalArgumentException("response content must be " + "either an object or an array"); } this.responseContent = responseContent; }
/** * @param content the content to set */ public void setContent(BsonValue content) { if (content != null && !(content.isDocument() || content.isArray())) { throw new IllegalArgumentException("content must be " + "either an object or an array"); } this.content = content; }
AggregateOperationImpl<T> hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
/** * Sets the hint for which index to use. A null value means no hint is set. * * @param hint the hint * @return this * @since 3.6 * @mongodb.server.release 3.6 */ public AggregateExplainOperation hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
public static void unescapeSchema(BsonDocument schema) { BsonValue unescaped = JsonUtils.unescapeKeys(schema); if (unescaped != null && unescaped.isDocument()) { List<String> keys = Lists.newArrayList(schema.keySet().iterator()); keys.stream().forEach(f -> schema.remove(f)); schema.putAll(unescaped.asDocument()); } }
public static void escapeSchema(BsonDocument schema) { BsonValue escaped = JsonUtils.escapeKeys(schema, false); if (escaped.isDocument()) { List<String> keys = Lists.newArrayList(schema.keySet().iterator()); keys.stream().forEach(f -> schema.remove(f)); schema.putAll(escaped.asDocument()); } }
public static boolean doesRequestUsesUpdateOperators(BsonValue content) { if (content.isDocument()) { return JsonUtils.containsUpdateOperators(content.asDocument()); } else if (content.isArray()) { BsonArray objs = content.asArray(); return objs.stream().allMatch(obj -> { if (obj.isDocument()) { return doesRequestUsesUpdateOperators(obj); } else { return true; } }); } else { return true; } }
private boolean hasFilterOnPassword(BsonDocument filters) { if (filters == null || filters.isEmpty()) { return false; } else { if (filters.isDocument()) { return filters.keySet().contains(propNamePassword) || filters .keySet().stream() .filter(key -> filters.get(key).isDocument()) .map(key -> filters.get(key).asDocument()) .anyMatch(doc -> hasFilterOnPassword(doc)); } else { return true; } } }
private static void flatten(String prefix, String key, BsonDocument data, BsonDocument set) { final String newPrefix = prefix == null ? key : prefix + "." + key; final BsonValue value = data.get(key); if (value.isDocument()) { value.asDocument() .keySet() .forEach(childKey -> flatten(newPrefix, childKey, value.asDocument(), set)); } else { set.append(newPrefix, value); } } }
public static List<RequestTransformer> getFromJson(BsonDocument props) throws InvalidMetadataException { BsonValue _rts = props.get(RTS_ELEMENT_NAME); if (_rts == null || !_rts.isArray()) { throw new InvalidMetadataException((_rts == null ? "missing '" : "invalid '") + RTS_ELEMENT_NAME + "' element; it must be an array"); } BsonArray rts = _rts.asArray(); List<RequestTransformer> ret = new ArrayList<>(); for (BsonValue o : rts.getValues()) { if (o.isDocument()) { ret.add(getSingleFromJson(o.asDocument())); } else { throw new InvalidMetadataException("invalid '" + RTS_ELEMENT_NAME + "'. Array elements must be json objects"); } } return ret; }
private void _transform(BsonDocument data) { data.keySet().stream().forEach(key -> { BsonValue value = data.get(key); if (value.isDocument()) { _transform(value.asDocument()); } else if (value.isObjectId()) { data.put(key, new BsonString(value .asObjectId() .getValue() .toString())); } }); } }
private BsonDocument createFilter(final String fieldName, final BsonValue value) { if (fieldName.startsWith("$")) { return new BsonDocument("$not", new BsonDocument(fieldName, value)); } else if ((value.isDocument() && containsOperator(value.asDocument())) || value.isRegularExpression()) { return new BsonDocument(fieldName, new BsonDocument("$not", value)); } return new BsonDocument(fieldName, new BsonDocument("$not", new BsonDocument("$eq", value))); }
private BsonArray unflattenArray(BsonArray array) { BsonArray unflattenArray = new BsonArray(); for (BsonValue value : array) { if (value.isArray()) { unflattenArray.add(unflattenArray(value.asArray())); } else if (value.isDocument()) { unflattenArray.add(new JsonUnflattener(value.asDocument()) .withSeparator(separator).unflatten()); } else { unflattenArray.add(value); } } return unflattenArray; }