Refine search
public void convertFieldValue(Entry<String, BsonValue> keyvalueforStruct, Struct struct, Schema schema) { Object colValue = null; String key = keyvalueforStruct.getKey(); BsonType type = keyvalueforStruct.getValue().getBsonType(); colValue = keyvalueforStruct.getValue().asString().getValue().toString(); break; colValue = keyvalueforStruct.getValue().asObjectId().getValue().toString(); break; schema.field(keyvalueforStruct.getKey()).schema().field("scope").schema()); jsStruct.put("code", keyvalueforStruct.getValue().asJavaScriptWithScope().getCode()); BsonDocument jwsDoc = keyvalueforStruct.getValue().asJavaScriptWithScope().getScope().asDocument(); for (Entry<String, BsonValue> jwsDocKey : jwsDoc.entrySet()) { convertFieldValue(jwsDocKey, jsScopeStruct, schema.field(keyvalueforStruct.getKey()).schema()); BsonDocument docs = keyvalueforStruct.getValue().asDocument(); for (Entry<String, BsonValue> doc : docs.entrySet()) { convertFieldValue(doc, documentStruct, documentSchema); list.add(temp); } else if (arrValue.getBsonType() == BsonType.OBJECT_ID && valueType == BsonType.OBJECT_ID) { String temp = arrValue.asObjectId().getValue().toString(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.DOUBLE && valueType == BsonType.DOUBLE) {
@Override public ObjectId uploadFromStream(final ClientSession clientSession, final String filename, final InputStream source, final GridFSUploadOptions options) { ObjectId id = new ObjectId(); uploadFromStream(clientSession, new BsonObjectId(id), filename, source, options); return id; }
private void pipeValue(final BsonValue value) { switch (value.getBsonType()) { case DOCUMENT: pipeDocument(value.asDocument()); break; case ARRAY: pipeArray(value.asArray()); break; case DOUBLE: break; case OBJECT_ID: writeObjectId(value.asObjectId().getValue()); break; case BOOLEAN:
/** * * @param exchange * @param properties */ public static void injectEtagHeader( HttpServerExchange exchange, BsonDocument properties) { if (properties == null) { return; } BsonValue _etag = properties.get("_etag"); if (_etag == null) { return; } if (_etag.isObjectId()) { setETagHeader(exchange, _etag.asObjectId().getValue().toString()); } else if (_etag.isString()) { setETagHeader(exchange, _etag.asString().getValue()); } }
ObjectId newEtag = new ObjectId(); content.put("_etag", new BsonObjectId(newEtag)); content.remove("_id"); // make sure we don't change this field BsonValue oldEtag = oldProperties.get("_etag"); if (ObjectId.isValid(requestEtag)) { _requestEtag = new BsonObjectId(new ObjectId(requestEtag)); } else {
= contentToTransform == null ? null : contentToTransform.asDocument(); content = context.getContent().asDocument(); } else { content = new BsonDocument(); context.getDocumentId()); content.put("id", new BsonString(uri.toString())); _contentToTransform.put("_$schema", $SCHEMA); content = context.getContent().asDocument(); } else { content = new BsonDocument(); if (!content.containsKey("_id")) { schemaId = new BsonObjectId(new ObjectId()); content.put( "id",
private void _transform(BsonDocument data, Set<String> propertiesNames) { data.keySet().stream().forEach(key -> { BsonValue value = data.get(key); if (shouldTransform(key, propertiesNames)) { if (value.isString() && ObjectId.isValid(value .asString() .getValue())) { data.put(key, new BsonObjectId( new ObjectId(value .asString() .getValue()))); } } if (value instanceof BsonDocument) { _transform(value.asDocument(), propertiesNames); } }); }
final int httpStatusIfOk) { BsonValue oldEtag = oldDocument.get("metadata", new BsonDocument()).asDocument().get("_etag"); if (ObjectId.isValid(requestEtag)) { _requestEtag = new BsonObjectId(new ObjectId(requestEtag)); } else {
.concat("/") .concat("_null"); } else if (docId.isString() && ObjectId.isValid(docId.asString().getValue())) { uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/") .concat(docId.asString().getValue()) .concat("?") .concat(DOC_ID_TYPE_QPARAM_KEY) uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/") .concat(docId.asObjectId().getValue().toString()); } else if (docId.isBoolean()) { uri = URLUtils.removeTrailingSlashes(parentUrl)
ObjectId newEtag = new ObjectId(); content.get("metadata", new BsonDocument()).asDocument().put("_etag", new BsonObjectId(newEtag));
switch (value.getBsonType()) { case INT32: return value.asInt32().getValue(); case INT64: return value.asInt64().getValue(); case STRING: return value.asString().getValue(); return value.asBoolean().getValue(); case OBJECT_ID: return value.asObjectId().getValue(); case DB_POINTER: return new DBRef(value.asDBPointer().getNamespace(), value.asDBPointer().getId()); return value.asArray().toArray(); case DOCUMENT: return Document.parse(value.asDocument().toJson()); default: return value;
@Override public BsonDocument generateIdIfAbsentFromDocument(final BsonDocument document) { if (!documentHasId(document)) { document.put(ID_FIELD_NAME, new BsonObjectId(new ObjectId())); } return document; }
public static DocValue translateBSON(BsonValue value) { if (value == null || value.isNull()) { return NullValue.INSTANCE; if (value.isDouble()) { return new DoubleValue(value.asDouble().getValue()); if (value.isString()) { if (value.isObjectId()) { ObjectId id = value.asObjectId().getValue(); byte[] bsonBytes = id.toByteArray(); return new TwelveBytesValue(bsonBytes);
@Override public void accept(BsonValue _document) { BsonDocument document = _document.asDocument(); // generate new id if missing, will be an insert if (!document.containsKey("_id")) { document .put("_id", new BsonObjectId(new ObjectId())); } // add the _etag document.put("_etag", new BsonObjectId(etag)); Bson _filter = eq("_id", document.get("_id")); if (shardKeys != null) { _filter = and(_filter, shardKeys); } if (filter != null && !filter.isEmpty()) { _filter = and(_filter, filter); } updates.add(new UpdateOneModel<>( _filter, getUpdateDocument(document), new UpdateOptions().upsert(true) )); } });
ObjectId etag = new ObjectId(); metadata.put("_etag", new BsonObjectId(etag)); if (metadata.get("_id") == null) { GridFSUploadOptions options = new GridFSUploadOptions() .metadata(Document.parse(metadata.toJson())); new BsonObjectId(etag), new BsonObjectId(_id)); } else { BsonValue _id = metadata.remove("_id"); new BsonObjectId(etag), _id);
= mdb.getCollection(collName, BsonDocument.class); ObjectId newEtag = new ObjectId(); content.put("_etag", new BsonObjectId(newEtag)); if (content.containsKey("_id")) { documentId = content.get("_id"); } else {
= mdb.getCollection(collName, BsonDocument.class); BsonObjectId newEtag = new BsonObjectId(new ObjectId()); .filter(d -> d != null && d.isDocument()) .forEachOrdered(document -> { document. asDocument() .put("_etag", newEtag); });
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())); } }); } }
) { BsonValue oldEtag = oldDocument.get("_etag"); DAOUtils.updateDocument( coll, oldDocument.get("_id"), null, shardKeys, DAOUtils.restoreDocument( coll, oldDocument.get("_id"), shardKeys, oldDocument, if (ObjectId.isValid(requestEtag)) { _requestEtag = new BsonObjectId(new ObjectId(requestEtag)); } else {
private static BsonObjectId getIdAsObjectId(String id) throws IllegalArgumentException { if (!ObjectId.isValid(id)) { throw new IllegalArgumentException("The id is not a valid ObjectId " + id); } return new BsonObjectId(new ObjectId(id)); }