Search in sources :

Example 86 with BsonInt32

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)));
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) Test(org.junit.jupiter.api.Test)

Example 87 with BsonInt32

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;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) BsonValue(org.bson.BsonValue)

Example 88 with BsonInt32

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;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 89 with BsonInt32

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());
    }
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) Test(org.junit.Test)

Example 90 with BsonInt32

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;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) WriteConcernError(com.mongodb.bulk.WriteConcernError) BulkWriteError(com.mongodb.bulk.BulkWriteError)

Aggregations

BsonInt32 (org.bson.BsonInt32)106 BsonDocument (org.bson.BsonDocument)91 BsonString (org.bson.BsonString)58 BsonArray (org.bson.BsonArray)26 Test (org.junit.Test)26 Document (org.bson.Document)23 BsonInt64 (org.bson.BsonInt64)20 Test (org.junit.jupiter.api.Test)16 BsonValue (org.bson.BsonValue)15 ArrayList (java.util.ArrayList)13 List (java.util.List)9 BsonDouble (org.bson.BsonDouble)9 DisplayName (org.junit.jupiter.api.DisplayName)8 BsonNull (org.bson.BsonNull)7 MongoClientSettings (com.mongodb.MongoClientSettings)6 TestCommandListener (com.mongodb.internal.connection.TestCommandListener)5 Map (java.util.Map)5 BsonBoolean (org.bson.BsonBoolean)5 ClusterFixture.serverVersionAtLeast (com.mongodb.ClusterFixture.serverVersionAtLeast)4 ServerAddress (com.mongodb.ServerAddress)4