use of org.bson.BsonString 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.BsonString 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.BsonString in project mongo-java-driver by mongodb.
the class BaseWriteOperation method manufactureGetLastErrorResponse.
private BsonDocument manufactureGetLastErrorResponse(final MongoBulkWriteException e) {
BsonDocument response = new BsonDocument();
addBulkWriteResultToResponse(e.getWriteResult(), response);
if (e.getWriteConcernError() != null) {
response.putAll(e.getWriteConcernError().getDetails());
}
if (getLastError(e) != null) {
response.put("err", new BsonString(getLastError(e).getMessage()));
response.put("code", new BsonInt32(getLastError(e).getCode()));
response.putAll(getLastError(e).getDetails());
} else if (e.getWriteConcernError() != null) {
response.put("err", new BsonString(e.getWriteConcernError().getMessage()));
response.put("code", new BsonInt32(e.getWriteConcernError().getCode()));
}
return response;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class CountOperation method getCommand.
private BsonDocument getCommand() {
BsonDocument document = new BsonDocument("count", new BsonString(namespace.getCollectionName()));
putIfNotNull(document, "query", filter);
putIfNotZero(document, "limit", limit);
putIfNotZero(document, "skip", skip);
putIfNotNull(document, "hint", hint);
putIfNotZero(document, "maxTimeMS", maxTimeMS);
if (!readConcern.isServerDefault()) {
document.put("readConcern", readConcern.asDocument());
}
if (collation != null) {
document.put("collation", collation.asDocument());
}
return document;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class CreateCollectionOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument document = new BsonDocument("create", new BsonString(collectionName));
document.put("autoIndexId", BsonBoolean.valueOf(autoIndex));
document.put("capped", BsonBoolean.valueOf(capped));
if (capped) {
putIfNotZero(document, "size", sizeInBytes);
putIfNotZero(document, "max", maxDocuments);
}
if (usePowerOf2Sizes != null) {
document.put("flags", new BsonInt32(1));
}
if (storageEngineOptions != null) {
document.put("storageEngine", storageEngineOptions);
}
if (indexOptionDefaults != null) {
document.put("indexOptionDefaults", indexOptionDefaults);
}
if (validator != null) {
document.put("validator", validator);
}
if (validationLevel != null) {
document.put("validationLevel", new BsonString(validationLevel.getValue()));
}
if (validationAction != null) {
document.put("validationAction", new BsonString(validationAction.getValue()));
}
appendWriteConcernToCommand(writeConcern, document, description);
if (collation != null) {
document.put("collation", collation.asDocument());
}
return document;
}
Aggregations