use of org.bson.BsonInt64 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.BsonInt64 in project mongo-java-driver by mongodb.
the class OperationHelper method cursorDocumentToQueryResult.
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);
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class AggregateOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument commandDocument = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName()));
commandDocument.put("pipeline", new BsonArray(pipeline));
if (maxTimeMS > 0) {
commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
}
if (!isInline(description)) {
BsonDocument cursor = new BsonDocument();
if (batchSize != null) {
cursor.put("batchSize", new BsonInt32(batchSize));
}
commandDocument.put("cursor", cursor);
}
if (allowDiskUse != null) {
commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
}
if (!readConcern.isServerDefault()) {
commandDocument.put("readConcern", readConcern.asDocument());
}
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
return commandDocument;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class AsyncQueryBatchCursor method asGetMoreCommandDocument.
private BsonDocument asGetMoreCommandDocument(final long cursorId) {
BsonDocument document = new BsonDocument("getMore", new BsonInt64(cursorId)).append("collection", new BsonString(namespace.getCollectionName()));
int batchSizeForGetMoreCommand = Math.abs(getNumberToReturn(limit, this.batchSize, count));
if (batchSizeForGetMoreCommand != 0) {
document.append("batchSize", new BsonInt32(batchSizeForGetMoreCommand));
}
if (maxTimeMS != 0) {
document.append("maxTimeMS", new BsonInt64(maxTimeMS));
}
return document;
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class CreateIndexesOperation method getIndex.
private BsonDocument getIndex(final IndexRequest request) {
BsonDocument index = new BsonDocument();
index.append("key", request.getKeys());
index.append("name", new BsonString(request.getName() != null ? request.getName() : generateIndexName(request.getKeys())));
index.append("ns", new BsonString(namespace.getFullName()));
if (request.isBackground()) {
index.append("background", BsonBoolean.TRUE);
}
if (request.isUnique()) {
index.append("unique", BsonBoolean.TRUE);
}
if (request.isSparse()) {
index.append("sparse", BsonBoolean.TRUE);
}
if (request.getExpireAfter(TimeUnit.SECONDS) != null) {
index.append("expireAfterSeconds", new BsonInt64(request.getExpireAfter(TimeUnit.SECONDS)));
}
if (request.getVersion() != null) {
index.append("v", new BsonInt32(request.getVersion()));
}
if (request.getWeights() != null) {
index.append("weights", request.getWeights());
}
if (request.getDefaultLanguage() != null) {
index.append("default_language", new BsonString(request.getDefaultLanguage()));
}
if (request.getLanguageOverride() != null) {
index.append("language_override", new BsonString(request.getLanguageOverride()));
}
if (request.getTextVersion() != null) {
index.append("textIndexVersion", new BsonInt32(request.getTextVersion()));
}
if (request.getSphereVersion() != null) {
index.append("2dsphereIndexVersion", new BsonInt32(request.getSphereVersion()));
}
if (request.getBits() != null) {
index.append("bits", new BsonInt32(request.getBits()));
}
if (request.getMin() != null) {
index.append("min", new BsonDouble(request.getMin()));
}
if (request.getMax() != null) {
index.append("max", new BsonDouble(request.getMax()));
}
if (request.getBucketSize() != null) {
index.append("bucketSize", new BsonDouble(request.getBucketSize()));
}
if (request.getDropDups()) {
index.append("dropDups", BsonBoolean.TRUE);
}
if (request.getStorageEngine() != null) {
index.append("storageEngine", request.getStorageEngine());
}
if (request.getPartialFilterExpression() != null) {
index.append("partialFilterExpression", request.getPartialFilterExpression());
}
if (request.getCollation() != null) {
index.append("collation", request.getCollation().asDocument());
}
return index;
}
Aggregations