use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class TestWindows method positionBased.
@Test
void positionBased() {
assertAll(() -> assertEquals(new BsonDocument("documents", new BsonArray(asList(new BsonInt32(-2), new BsonInt32(0)))), documents(-2, 0).toBsonDocument()), () -> assertEquals(new BsonDocument("documents", new BsonArray(asList(new BsonString(CURRENT.value()), new BsonInt32(Integer.MAX_VALUE)))), documents(CURRENT, Integer.MAX_VALUE).toBsonDocument()), () -> assertEquals(new BsonDocument("documents", new BsonArray(asList(new BsonInt32(0), new BsonString(UNBOUNDED.value())))), documents(0, UNBOUNDED).toBsonDocument()), () -> assertEquals(new BsonDocument("documents", new BsonArray(asList(new BsonString(CURRENT.value()), new BsonString(UNBOUNDED.value())))), documents(CURRENT, UNBOUNDED).toBsonDocument()));
assertAll(() -> assertThrows(IllegalArgumentException.class, () -> documents(1, -1)), () -> assertThrows(IllegalArgumentException.class, () -> documents(CURRENT, -1)), () -> assertThrows(IllegalArgumentException.class, () -> documents(1, CURRENT)), () -> assertThrows(IllegalArgumentException.class, () -> documents(null, 1)), () -> assertThrows(IllegalArgumentException.class, () -> documents(1, null)), () -> assertThrows(IllegalArgumentException.class, () -> documents(null, null)));
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class AggregateToCollectionOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
validateCollation(description, collation);
BsonValue aggregationTarget = (aggregationLevel == AggregationLevel.DATABASE) ? new BsonInt32(1) : new BsonString(namespace.getCollectionName());
BsonDocument commandDocument = new BsonDocument("aggregate", aggregationTarget);
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 (readConcern != null && !readConcern.isServerDefault() && serverIsAtLeastVersionThreeDotFour(description)) {
commandDocument.put("readConcern", readConcern.asDocument());
}
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
if (comment != null) {
commandDocument.put("comment", new BsonString(comment));
}
if (hint != null) {
commandDocument.put("hint", hint);
}
if (variables != null) {
commandDocument.put("let", variables);
}
return commandDocument;
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class X509Authenticator method getAuthCommand.
private BsonDocument getAuthCommand(final String userName) {
BsonDocument cmd = new BsonDocument();
cmd.put("authenticate", new BsonInt32(1));
if (userName != null) {
cmd.put("user", new BsonString(userName));
}
cmd.put("mechanism", new BsonString(AuthenticationMechanism.MONGODB_X509.getMechanismName()));
return cmd;
}
use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.
the class CommandResultTest method testCommandFailure.
@Test
public void testCommandFailure() throws UnknownHostException {
try {
new CommandResult(new BsonDocument("ok", new BsonInt32(0)).append("errmsg", new BsonString("ns not found")).append("code", new BsonInt32(5000)), DECODER, new ServerAddress()).throwOnError();
fail("Should throw");
} catch (MongoCommandException e) {
assertEquals(5000, e.getCode());
}
}
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);
WriteConcernError writeConcernError = e.getWriteConcernError();
if (writeConcernError != null) {
response.putAll(writeConcernError.getDetails());
}
BulkWriteError lastError = getLastError(e);
if (lastError != null) {
response.put("err", new BsonString(lastError.getMessage()));
response.put("code", new BsonInt32(lastError.getCode()));
response.putAll(lastError.getDetails());
} else if (writeConcernError != null) {
response.put("err", new BsonString(writeConcernError.getMessage()));
response.put("code", new BsonInt32(writeConcernError.getCode()));
}
return response;
}
Aggregations