@Override public String apply(final BsonDocument result) { return result.getString("name").getValue(); } });
@Override public String apply(final BsonDocument result) { return result.getString("name").getValue(); } });
@Override public String apply(final BsonDocument result) { return result.getString("name").getValue(); } });
@Override public void encode(final BsonWriter writer, final BsonString value, final EncoderContext encoderContext) { writer.writeString(value.getValue()); }
@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 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; }
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); }
private static String getString(final BsonDocument response, final String key) { if (response.containsKey(key)) { return response.getString(key).getValue(); } else { return null; } }
static String getErrorMessage(final BsonDocument response, final String errorMessageFieldName) { return response.getString(errorMessageFieldName, new BsonString("")).getValue(); }
private static String extractErrorCodeName(final BsonDocument response) { return response.getString("codeName", new BsonString("")).getValue(); }
private static String extractErrorMessage(final BsonDocument response) { String errorMessage = response.getString("errmsg", new BsonString("")).getValue(); // Satisfy nullability checker if (errorMessage == null) { throw new MongoInternalException("This value should not be null"); } return errorMessage; } }
private List<T> projectFromFullNamespaceToCollectionName(final List<BsonDocument> unstripped) { if (unstripped == null) { return null; } List<T> stripped = new ArrayList<T>(unstripped.size()); String prefix = databaseName + "."; for (BsonDocument cur : unstripped) { String name = cur.getString("name").getValue(); String collectionName = name.substring(prefix.length()); cur.put("name", new BsonString(collectionName)); stripped.add(decoder.decode(new BsonDocumentReader(cur), DecoderContext.builder().build())); } return stripped; } }
public static WriteConcernError createWriteConcernError(final BsonDocument writeConcernErrorDocument) { return new WriteConcernError(writeConcernErrorDocument.getNumber("code").intValue(), writeConcernErrorDocument.getString("codeName", new BsonString("")).getValue(), writeConcernErrorDocument.getString("errmsg").getValue(), writeConcernErrorDocument.getDocument("errInfo", new BsonDocument())); }
private static <T> QueryResult<T> cursorDocumentToQueryResult(final BsonDocument cursorDocument, final ServerAddress serverAddress, final String fieldNameContainingBatch) { long cursorId = ((BsonInt64) cursorDocument.get("id")).getValue(); MongoNamespace queryResultNamespace = new MongoNamespace(cursorDocument.getString("ns").getValue()); return new QueryResult<T>(queryResultNamespace, BsonDocumentWrapperHelper.<T>toList(cursorDocument, fieldNameContainingBatch), cursorId, serverAddress); }
/** * 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()); } }
@SuppressWarnings("unchecked") private static List<BulkWriteError> getWriteErrors(final BsonDocument result) { List<BulkWriteError> writeErrors = new ArrayList<BulkWriteError>(); BsonArray writeErrorsDocuments = (BsonArray) result.get("writeErrors"); if (writeErrorsDocuments != null) { for (BsonValue cur : writeErrorsDocuments) { BsonDocument curDocument = (BsonDocument) cur; writeErrors.add(new BulkWriteError(curDocument.getNumber("code").intValue(), curDocument.getString("errmsg").getValue(), curDocument.getDocument("errInfo", new BsonDocument()), curDocument.getNumber("index").intValue())); } } return writeErrors; }
@SuppressWarnings("unchecked") private List<BulkWriteError> getWriteErrors(final BsonDocument result) { List<BulkWriteError> writeErrors = new ArrayList<BulkWriteError>(); BsonArray writeErrorsDocuments = (BsonArray) result.get("writeErrors"); if (writeErrorsDocuments != null) { for (BsonValue cur : writeErrorsDocuments) { BsonDocument curDocument = (BsonDocument) cur; writeErrors.add(new BulkWriteError(curDocument.getNumber("code").intValue(), curDocument.getString("errmsg").getValue(), curDocument.getDocument("errInfo", new BsonDocument()), curDocument.getNumber("index").intValue())); } } return writeErrors; }
@Override public void authenticate(final InternalConnection connection, final ConnectionDescription connectionDescription) { try { BsonDocument nonceResponse = executeCommand(getMongoCredential().getSource(), getNonceCommand(), connection); BsonDocument authCommand = getAuthCommand(getUserNameNonNull(), getPasswordNonNull(), ((BsonString) nonceResponse.get("nonce")).getValue()); executeCommand(getMongoCredential().getSource(), authCommand, connection); } catch (MongoCommandException e) { throw new MongoSecurityException(getMongoCredential(), "Exception authenticating", e); } }
@Override protected void doWriteEndDocument() { BsonValue value = getContext().container; setContext(getContext().getParentContext()); if (getContext().getContextType() == BsonContextType.JAVASCRIPT_WITH_SCOPE) { BsonDocument scope = (BsonDocument) value; BsonString code = (BsonString) getContext().container; setContext(getContext().getParentContext()); write(new BsonJavaScriptWithScope(code.getValue(), scope)); } else if (getContext().getContextType() != BsonContextType.TOP_LEVEL) { write(value); } }