use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class X509Authenticator method getAuthCommand.
private BsonDocument getAuthCommand(final String userName) {
BsonDocument cmd = new BsonDocument();
cmd.put("authenticate", new BsonInt32(1));
if (userName != null) {
cmd.put("user", new BsonString(userName));
}
cmd.put("mechanism", new BsonString(AuthenticationMechanism.MONGODB_X509.getMechanismName()));
return cmd;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class QueryProtocol method asFindCommandResponseDocument.
private BsonDocument asFindCommandResponseDocument(final ResponseBuffers responseBuffers, final QueryResult<T> queryResult, final boolean isExplain) {
List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
if (responseBuffers.getReplyHeader().getNumberReturned() > 0) {
responseBuffers.getBodyByteBuffer().position(0);
rawResultDocuments = ByteBufBsonDocument.create(responseBuffers);
}
if (isExplain) {
BsonDocument explainCommandResponseDocument = new BsonDocument("ok", new BsonDouble(1));
explainCommandResponseDocument.putAll(rawResultDocuments.get(0));
return explainCommandResponseDocument;
} else {
BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("firstBatch", new BsonArray(rawResultDocuments));
return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
}
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class QueryProtocol method asFindCommandDocument.
private BsonDocument asFindCommandDocument(final ByteBufferBsonOutput bsonOutput, final int firstDocumentPosition) {
BsonDocument command = new BsonDocument(FIND_COMMAND_NAME, new BsonString(namespace.getCollectionName()));
boolean isExplain = false;
List<ByteBufBsonDocument> documents = ByteBufBsonDocument.create(bsonOutput, firstDocumentPosition);
ByteBufBsonDocument rawQueryDocument = documents.get(0);
for (Map.Entry<String, BsonValue> cur : rawQueryDocument.entrySet()) {
String commandFieldName = META_OPERATOR_TO_COMMAND_FIELD_MAP.get(cur.getKey());
if (commandFieldName != null) {
command.append(commandFieldName, cur.getValue());
} else if (cur.getKey().equals("$explain")) {
isExplain = true;
}
}
if (command.size() == 1) {
command.append("filter", rawQueryDocument);
}
if (documents.size() == 2) {
command.append("projection", documents.get(1));
}
if (skip != 0) {
command.append("skip", new BsonInt32(skip));
}
if (withLimitAndBatchSize) {
if (limit != 0) {
command.append("limit", new BsonInt32(limit));
}
if (batchSize != 0) {
command.append("batchSize", new BsonInt32(batchSize));
}
}
if (tailableCursor) {
command.append("tailable", BsonBoolean.valueOf(tailableCursor));
}
if (noCursorTimeout) {
command.append("noCursorTimeout", BsonBoolean.valueOf(noCursorTimeout));
}
if (oplogReplay) {
command.append("oplogReplay", BsonBoolean.valueOf(oplogReplay));
}
if (awaitData) {
command.append("awaitData", BsonBoolean.valueOf(awaitData));
}
if (partial) {
command.append("allowPartialResults", BsonBoolean.valueOf(partial));
}
if (isExplain) {
command = new BsonDocument(EXPLAIN_COMMAND_NAME, command);
}
return command;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class MapReduceToCollectionOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument outputDocument = new BsonDocument(getAction(), new BsonString(getCollectionName()));
outputDocument.append("sharded", BsonBoolean.valueOf(isSharded()));
outputDocument.append("nonAtomic", BsonBoolean.valueOf(isNonAtomic()));
if (getDatabaseName() != null) {
outputDocument.put("db", new BsonString(getDatabaseName()));
}
BsonDocument commandDocument = new BsonDocument("mapreduce", new BsonString(namespace.getCollectionName())).append("map", getMapFunction()).append("reduce", getReduceFunction()).append("out", outputDocument).append("query", asValueOrNull(getFilter())).append("sort", asValueOrNull(getSort())).append("finalize", asValueOrNull(getFinalizeFunction())).append("scope", asValueOrNull(getScope())).append("verbose", BsonBoolean.valueOf(isVerbose()));
putIfNotZero(commandDocument, "limit", getLimit());
putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS));
putIfTrue(commandDocument, "jsMode", isJsMode());
if (bypassDocumentValidation != null && description != null && serverIsAtLeastVersionThreeDotTwo(description)) {
commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation));
}
if (description != null) {
appendWriteConcernToCommand(writeConcern, commandDocument, description);
}
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
return commandDocument;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class RenameCollectionOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument commandDocument = new BsonDocument("renameCollection", new BsonString(originalNamespace.getFullName())).append("to", new BsonString(newNamespace.getFullName())).append("dropTarget", BsonBoolean.valueOf(dropTarget));
appendWriteConcernToCommand(writeConcern, commandDocument, description);
return commandDocument;
}
Aggregations