use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class WriteProtocol method getResponseDocument.
private BsonDocument getResponseDocument(final RequestMessage curMessage, final RequestMessage nextMessage, final WriteConcernResult writeConcernResult, final WriteConcernException writeConcernException) {
BsonDocument response = new BsonDocument("ok", new BsonInt32(1));
if (writeConcern.isAcknowledged()) {
if (writeConcernException == null) {
appendToWriteCommandResponseDocument(curMessage, nextMessage, writeConcernResult, response);
} else {
response.put("n", new BsonInt32(0));
BsonDocument writeErrorDocument = new BsonDocument("index", new BsonInt32(0)).append("code", new BsonInt32(writeConcernException.getErrorCode()));
if (writeConcernException.getErrorMessage() != null) {
writeErrorDocument.append("errmsg", new BsonString(writeConcernException.getErrorMessage()));
}
response.put("writeErrors", new BsonArray(singletonList(writeErrorDocument)));
}
}
return response;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class AggregateExplainOperation method getCommand.
private BsonDocument getCommand() {
BsonDocument commandDocument = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName()));
commandDocument.put("pipeline", new BsonArray(pipeline));
commandDocument.put("explain", BsonBoolean.TRUE);
if (maxTimeMS > 0) {
commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
}
if (allowDiskUse != null) {
commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
}
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
return commandDocument;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class AggregateToCollectionOperation 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 (allowDiskUse != null) {
commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
}
if (bypassDocumentValidation != null && serverIsAtLeastVersionThreeDotTwo(description)) {
commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation));
}
if (serverIsAtLeastVersionThreeDotSix(description)) {
commandDocument.put("cursor", new BsonDocument());
}
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 CreateIndexesOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument command = new BsonDocument("createIndexes", new BsonString(namespace.getCollectionName()));
List<BsonDocument> values = new ArrayList<BsonDocument>();
for (IndexRequest request : requests) {
values.add(getIndex(request));
}
command.put("indexes", new BsonArray(values));
appendWriteConcernToCommand(writeConcern, command, description);
return command;
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class GridFSTest method doDelete.
private void doDelete(final BsonDocument arguments, final BsonDocument assertion) {
Throwable error = null;
try {
gridFSBucket.delete(arguments.getObjectId("id").getValue());
} catch (MongoGridFSException e) {
error = e;
}
if (assertion.containsKey("error")) {
assertNotNull("Should have thrown an exception", error);
} else {
assertNull("Should not have thrown an exception", error);
for (BsonValue rawDataItem : assertion.getArray("data")) {
BsonDocument dataItem = rawDataItem.asDocument();
for (BsonValue deletedItem : dataItem.getArray("deletes", new BsonArray())) {
String delete = dataItem.getString("delete", new BsonString("none")).getValue();
BsonObjectId id = new BsonObjectId(new ObjectId());
if (delete.equals("expected.files")) {
id = deletedItem.asDocument().getDocument("q").getObjectId("_id");
} else if (delete.equals("expected.chunks")) {
id = deletedItem.asDocument().getDocument("q").getObjectId("files_id");
}
assertEquals(filesCollection.count(new BsonDocument("_id", id)), 0);
assertEquals(chunksCollection.count(new BsonDocument("files_id", id)), 0);
}
}
}
}
Aggregations