use of org.bson.BsonInt32 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.BsonInt32 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.BsonInt32 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.BsonInt32 in project mongo-java-driver by mongodb.
the class BaseWriteOperation method addBulkWriteResultToResponse.
private void addBulkWriteResultToResponse(final BulkWriteResult bulkWriteResult, final BsonDocument response) {
response.put("ok", new BsonInt32(1));
if (getType() == INSERT) {
response.put("n", new BsonInt32(0));
} else if (getType() == DELETE) {
response.put("n", new BsonInt32(bulkWriteResult.getDeletedCount()));
} else if (getType() == UPDATE || getType() == REPLACE) {
response.put("n", new BsonInt32(bulkWriteResult.getMatchedCount() + bulkWriteResult.getUpserts().size()));
if (bulkWriteResult.getUpserts().isEmpty()) {
response.put("updatedExisting", BsonBoolean.TRUE);
} else {
response.put("updatedExisting", BsonBoolean.FALSE);
response.put("upserted", bulkWriteResult.getUpserts().get(0).getId());
}
}
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class UpdateProtocol method appendToWriteCommandResponseDocument.
@Override
protected void appendToWriteCommandResponseDocument(final RequestMessage curMessage, final RequestMessage nextMessage, final WriteConcernResult writeConcernResult, final BsonDocument response) {
response.append("n", new BsonInt32(writeConcernResult.getCount()));
UpdateMessage updateMessage = (UpdateMessage) curMessage;
UpdateRequest updateRequest = updateMessage.getUpdateRequests().get(0);
BsonValue upsertedId = null;
if (writeConcernResult.getUpsertedId() != null) {
upsertedId = writeConcernResult.getUpsertedId();
} else if (!writeConcernResult.isUpdateOfExisting() && updateRequest.isUpsert()) {
if (updateRequest.getUpdate().containsKey("_id")) {
upsertedId = updateRequest.getUpdate().get("_id");
} else if (updateRequest.getFilter().containsKey("_id")) {
upsertedId = updateRequest.getFilter().get("_id");
}
}
if (upsertedId != null) {
response.append("upserted", new BsonArray(singletonList(new BsonDocument("index", new BsonInt32(0)).append("_id", upsertedId))));
}
}
Aggregations