@Override public BsonValue remove(final Object key) { return getUnwrapped().remove(key); }
private static Bson combine(final List<String> fieldNames, final BsonValue value) { BsonDocument document = new BsonDocument(); for (String fieldName : fieldNames) { document.remove(fieldName); document.append(fieldName, value); } return document; } }
private BsonDocument getInsertDocument(R record, BsonDocument key) { BsonDocument valueDocument = BsonDocument.parse(record.value().toString()); valueDocument.remove("_id"); valueDocument.append("id", key.get("id")); return valueDocument; }
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument combinedDocument = new BsonDocument(); for (Bson sort : projections) { BsonDocument sortDocument = sort.toBsonDocument(documentClass, codecRegistry); for (String key : sortDocument.keySet()) { combinedDocument.remove(key); combinedDocument.append(key, sortDocument.get(key)); } } return combinedDocument; }
valueDocument.remove("_id");
@Override public GridFSFile decode(final BsonReader reader, final DecoderContext decoderContext) { BsonDocument bsonDocument = bsonDocumentCodec.decode(reader, decoderContext); BsonValue id = bsonDocument.get("_id"); String filename = bsonDocument.get("filename", new BsonString("")).asString().getValue(); long length = bsonDocument.getNumber("length").longValue(); int chunkSize = bsonDocument.getNumber("chunkSize").intValue(); Date uploadDate = new Date(bsonDocument.getDateTime("uploadDate").getValue()); String md5 = bsonDocument.containsKey("md5") ? bsonDocument.getString("md5").getValue() : null; BsonDocument metadataBsonDocument = bsonDocument.getDocument("metadata", new BsonDocument()); Document optionalMetadata = asDocumentOrNull(metadataBsonDocument); for (String key : VALID_FIELDS) { bsonDocument.remove(key); } Document deprecatedExtraElements = asDocumentOrNull(bsonDocument); return new GridFSFile(id, filename, length, chunkSize, uploadDate, md5, optionalMetadata, deprecatedExtraElements); }
private static Bson combine(final List<String> fieldNames, final BsonValue value) { BsonDocument document = new BsonDocument(); for (String fieldName : fieldNames) { document.remove(fieldName); document.append(fieldName, value); } return document; } }
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()); } }
/** * Filter out reserved keys, removing them from request * * The _ prefix is reserved for RESTHeart-generated properties (_id is * allowed) * * @param content * @param context */ private static void filterOutReservedKeys( final BsonDocument content, final RequestContext context) { final HashSet<String> keysToRemove = new HashSet<>(); content.keySet().stream() .filter(key -> key.startsWith("_") && !key.equals(_ID)) .forEach(key -> { keysToRemove.add(key); }); keysToRemove.stream().map(keyToRemove -> { content.remove(keyToRemove); return keyToRemove; }).forEach(keyToRemove -> { context.addWarning("Reserved field " + keyToRemove + " was filtered out from the request"); }); }
root.remove("version"); root.forEach((groupKey, groupContent) -> groupContent.asDocument().forEach((metricKey, metricContent) -> {
public BsonDocument asBsonDocument() { if (embedded == null || embedded.isEmpty()) { properties.remove(EMBEDDED); } else { properties.append(EMBEDDED, embedded); } if (links == null || links.isEmpty()) { properties.remove(LINKS); } else { properties.append(LINKS, links); } if (links != null && !links.isEmpty()) { properties.append(LINKS, links); } return properties; }
/** * * @param dbName * @param collName * @return */ List<BsonDocument> getCollectionIndexes(String dbName, String collName) { List<BsonDocument> ret = new ArrayList<>(); ListIndexesIterable<Document> indexes = client .getDatabase(dbName) .getCollection(collName, BsonDocument.class) .listIndexes(); indexes.iterator().forEachRemaining( i -> { BsonDocument bi = BsonDocument.parse(i.toJson()); BsonValue name = bi.remove("name"); bi.put("_id", name); ret.add(bi); }); return ret; }
@Override public WriteModel<BsonDocument> createWriteModel(SinkDocument document) { BsonDocument vd = document.getValueDoc().orElseThrow( () -> new DataException("error: cannot build the WriteModel since" + " the value document was missing unexpectedly") ); BsonValue businessKey = vd.get(DBCollection.ID_FIELD_NAME); if(businessKey == null || !(businessKey instanceof BsonDocument)) { throw new DataException("error: cannot build the WriteModel since" + " the value document does not contain an _id field of type BsonDocument" + " which holds the business key fields"); } vd.remove(DBCollection.ID_FIELD_NAME); return new ReplaceOneModel<>((BsonDocument)businessKey, vd, UPDATE_OPTIONS); } }
@Override public WriteModel<BsonDocument> createWriteModel(SinkDocument document) { BsonDocument vd = document.getValueDoc().orElseThrow( () -> new DataException("error: cannot build the WriteModel since" + " the value document was missing unexpectedly") ); BsonValue businessKey = vd.get(DBCollection.ID_FIELD_NAME); if(businessKey == null || !(businessKey instanceof BsonDocument)) { throw new DataException("error: cannot build the WriteModel since" + " the value document does not contain an _id field of type BsonDocument" + " which holds the business key fields"); } vd.remove(DBCollection.ID_FIELD_NAME); return new ReplaceOneModel<>((BsonDocument)businessKey, vd, UPDATE_OPTIONS); } }
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument combinedDocument = new BsonDocument(); for (Bson sort : projections) { BsonDocument sortDocument = sort.toBsonDocument(documentClass, codecRegistry); for (String key : sortDocument.keySet()) { combinedDocument.remove(key); combinedDocument.append(key, sortDocument.get(key)); } } return combinedDocument; }
String prop = _prop.asString().getValue(); _contentToTransform.remove(prop); } else { context.addWarning("property in the args list "
@Override public GridFSFile decode(final BsonReader reader, final DecoderContext decoderContext) { BsonDocument bsonDocument = bsonDocumentCodec.decode(reader, decoderContext); BsonValue id = bsonDocument.get("_id"); String filename = bsonDocument.get("filename", new BsonString("")).asString().getValue(); long length = bsonDocument.getNumber("length").longValue(); int chunkSize = bsonDocument.getNumber("chunkSize").intValue(); Date uploadDate = new Date(bsonDocument.getDateTime("uploadDate").getValue()); String md5 = bsonDocument.containsKey("md5") ? bsonDocument.getString("md5").getValue() : null; BsonDocument metadataBsonDocument = bsonDocument.getDocument("metadata", new BsonDocument()); Document optionalMetadata = asDocumentOrNull(metadataBsonDocument); for (String key : VALID_FIELDS) { bsonDocument.remove(key); } Document deprecatedExtraElements = asDocumentOrNull(bsonDocument); return new GridFSFile(id, filename, length, chunkSize, uploadDate, md5, optionalMetadata, deprecatedExtraElements); }