use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class MapReduceWithInlineResultsOperation method getCommand.
private BsonDocument getCommand(final SessionContext sessionContext, final int maxWireVersion) {
BsonDocument commandDocument = new BsonDocument("mapreduce", new BsonString(namespace.getCollectionName())).append("map", getMapFunction()).append("reduce", getReduceFunction()).append("out", new BsonDocument("inline", new BsonInt32(1)));
putIfNotNull(commandDocument, "query", getFilter());
putIfNotNull(commandDocument, "sort", getSort());
putIfNotNull(commandDocument, "finalize", getFinalizeFunction());
putIfNotNull(commandDocument, "scope", getScope());
putIfTrue(commandDocument, "verbose", isVerbose());
appendReadConcernToCommand(sessionContext, maxWireVersion, commandDocument);
putIfNotZero(commandDocument, "limit", getLimit());
putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS));
putIfTrue(commandDocument, "jsMode", isJsMode());
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;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class UnifiedCrudHelper method executeDistinct.
OperationResult executeDistinct(final BsonDocument operation) {
MongoCollection<BsonDocument> collection = entities.getCollection(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments");
ClientSession session = getSession(arguments);
BsonString fieldName = arguments.getString("fieldName");
DistinctIterable<BsonValue> iterable = session == null ? collection.distinct(fieldName.getValue(), BsonValue.class) : collection.distinct(session, fieldName.getValue(), BsonValue.class);
for (Map.Entry<String, BsonValue> cur : arguments.entrySet()) {
switch(cur.getKey()) {
case "fieldName":
case "session":
break;
case "filter":
iterable.filter(cur.getValue().asDocument());
break;
default:
throw new UnsupportedOperationException("Unsupported argument: " + cur.getKey());
}
}
return resultOf(() -> new BsonArray(iterable.into(new ArrayList<>())));
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class UnifiedGridFSHelper method executeDownload.
public OperationResult executeDownload(final BsonDocument operation) {
GridFSBucket bucket = entities.getBucket(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments");
BsonValue id = arguments.get("id");
if (arguments.size() > 1) {
throw new UnsupportedOperationException("Unexpected arguments");
}
requireNonNull(id);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bucket.downloadToStream(id, baos);
return OperationResult.of(new BsonString(HexUtils.toHex(baos.toByteArray())));
} catch (Exception e) {
return OperationResult.of(e);
}
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class GetMoreProtocol method asGetMoreCommandResponseDocument.
private BsonDocument asGetMoreCommandResponseDocument(final QueryResult<T> queryResult, final ResponseBuffers responseBuffers) {
List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
if (responseBuffers.getReplyHeader().getNumberReturned() != 0) {
responseBuffers.reset();
rawResultDocuments = ByteBufBsonDocument.createList(responseBuffers);
}
BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("nextBatch", new BsonArray(rawResultDocuments));
return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
}
Aggregations