@Override protected String doReadString() { return currentValue.asString().getValue(); }
private static Set<String> listToSet(final BsonArray array) { if (array == null || array.isEmpty()) { return Collections.emptySet(); } else { Set<String> set = new HashSet<String>(); for (BsonValue value : array) { set.add(value.asString().getValue()); } return set; } }
private static TagSet getTagSetFromDocument(final BsonDocument tagsDocuments) { List<Tag> tagList = new ArrayList<Tag>(); for (final Map.Entry<String, BsonValue> curEntry : tagsDocuments.entrySet()) { tagList.add(new Tag(curEntry.getKey(), curEntry.getValue().asString().getValue())); } return new TagSet(tagList); }
/** * Gets the value of the key if it is a BsonString, or throws if not. * * @param key the key * @return the value of the key as a BsonString * @throws org.bson.BsonInvalidOperationException if the document does not contain the key or the value is not of the expected type */ public BsonString getString(final Object key) { throwIfKeyAbsent(key); return get(key).asString(); }
private static List<String> getCompressors(final BsonDocument isMasterResult) { List<String> compressorList = new ArrayList<String>(); for (BsonValue compressor : isMasterResult.getArray("compression", new BsonArray())) { compressorList.add(compressor.asString().getValue()); } return compressorList; }
/** * If the document does not contain the given key, return the given default value. Otherwise, gets the value of the key as a * BsonString. * * @param key the key * @param defaultValue the default value * @return the value of the key as a BsonString * @throws org.bson.BsonInvalidOperationException if the document contains the key but the value is not of the expected type */ public BsonString getString(final Object key, final BsonString defaultValue) { if (!containsKey(key)) { return defaultValue; } return get(key).asString(); }
/** * Construct a new instance with the CommandResult from a failed command * * @param response the command response * @param address the address of the server that generated the response */ public MongoCommandException(final BsonDocument response, final ServerAddress address) { super(extractErrorCode(response), format("Command failed with error %s: '%s' on server %s. The full response is %s", extractErrorCodeAndName(response), extractErrorMessage(response), address, getResponseAsJson(response)), address); this.response = response; for (BsonValue curErrorLabel : response.getArray("errorLabels", new BsonArray())) { addLabel(curErrorLabel.asString().getValue()); } }
@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); }
String codeName = ((MongoCommandException) exception).getResponse().get("codeName").asString().getValue(); int errorCode = ((MongoCommandException) exception).getErrorCode();
@Override @SuppressWarnings("deprecation") public ReadOperation<BatchCursor<TResult>> asReadOperation() { BsonValue outCollection = getOutCollection(); if (outCollection != null) { getExecutor().execute(operations.aggregateToCollection(pipeline, maxTimeMS, allowDiskUse, bypassDocumentValidation, collation, hint, comment, aggregationLevel), getReadConcern(), getClientSession()); FindOptions findOptions = new FindOptions().collation(collation); Integer batchSize = getBatchSize(); if (batchSize != null) { findOptions.batchSize(batchSize); } return operations.find(new MongoNamespace(namespace.getDatabaseName(), outCollection.asString().getValue()), new BsonDocument(), resultClass, findOptions); } else { return operations.aggregate(pipeline, resultClass, maxTimeMS, maxAwaitTimeMS, getBatchSize(), collation, hint, comment, allowDiskUse, useCursor, aggregationLevel); } }
executor.execute(operation, getReadConcern()); if (returnCursorForOutCollection) { return new DBCursor(database.getCollection(outCollection.asString().getValue()), new BasicDBObject(), new DBCollectionFindOptions().readPreference(primary()).collation(options.getCollation())); } else {
return value.asInt64().getValue(); case STRING: return value.asString().getValue(); case DECIMAL128: return value.asDecimal128().doubleValue();
check(doc.get("double").asDouble().getValue()).is(42.42D); check(doc.get("string").getBsonType()).is(BsonType.STRING); check(doc.get("string").asString().getValue()).is("foo"); check(doc.get("null").getBsonType()).is(BsonType.NULL); check(doc.get("null").isNull());
break; case STRING: writeString(value.asString().getValue()); break; case BINARY:
private static Set<String> listToSet(final BsonArray array) { if (array == null || array.isEmpty()) { return Collections.emptySet(); } else { Set<String> set = new HashSet<String>(); for (BsonValue value : array) { set.add(value.asString().getValue()); } return set; } }
return value.asInt64().getValue(); case STRING: return value.asString().getValue(); case DECIMAL128: return value.asDecimal128().doubleValue();
private static String getIdString(BsonValue id) throws UnsupportedDocumentIdException { if (id == null) { return null; } else if (id.isString()) { return "'" + id.asString().getValue() + "'"; } else { return JsonUtils.minify(JsonUtils.toJson(id) .replace("\"", "'")); } }
@Override public String getSrcAddr() { return first(get(document, "flows", "0:3", "src_ip"), get(document, "flows", "0:4", "src_ip"), get(document, "flows", "0:1", "ipv4", "src_ip"), get(document, "flows", "0:1", "ipv6", "src_ip")) .map(v -> v.asString().getValue()) .orElse(null); }
@Override public String getDstAddr() { return first(get(document, "flows", "0:3", "dst_ip"), get(document, "flows", "0:4", "dst_ip"), get(document, "flows", "0:1", "ipv4", "dst_ip"), get(document, "flows", "0:1", "ipv6", "dst_ip")) .map(v -> v.asString().getValue()) .orElse(null); }