Search in sources :

Example 91 with BsonInt32

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

Example 92 with BsonInt32

use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.

the class QueryBatchCursor method asGetMoreCommandDocument.

private BsonDocument asGetMoreCommandDocument(final ServerCursor serverCursor) {
    BsonDocument document = new BsonDocument("getMore", new BsonInt64(serverCursor.getId())).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;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 93 with BsonInt32

use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.

the class EstimatedDocumentCountOperation method getAggregateCommand.

private BsonDocument getAggregateCommand(final SessionContext sessionContext, final ConnectionDescription connectionDescription) {
    BsonDocument document = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName())).append("cursor", new BsonDocument()).append("pipeline", new BsonArray(asList(new BsonDocument("$collStats", new BsonDocument("count", new BsonDocument())), new BsonDocument("$group", new BsonDocument("_id", new BsonInt32(1)).append("n", new BsonDocument("$sum", new BsonString("$count")))))));
    appendReadConcernToCommand(sessionContext, connectionDescription.getMaxWireVersion(), document);
    putIfNotZero(document, "maxTimeMS", maxTimeMS);
    return document;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray)

Example 94 with BsonInt32

use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.

the class DropDatabaseOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = new BsonDocument("dropDatabase", new BsonInt32(1));
    appendWriteConcernToCommand(writeConcern, commandDocument, description);
    return commandDocument;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument)

Example 95 with BsonInt32

use of org.bson.BsonInt32 in project mongo-java-driver by mongodb.

the class JsonPoweredCrudTestHelper method toResult.

BsonDocument toResult(final UpdateResult updateResult) {
    BsonDocument resultDoc = new BsonDocument("matchedCount", new BsonInt32((int) updateResult.getMatchedCount()));
    resultDoc.append("modifiedCount", new BsonInt32((int) updateResult.getModifiedCount()));
    if (updateResult.getUpsertedId() != null) {
        resultDoc.append("upsertedId", updateResult.getUpsertedId());
    }
    resultDoc.append("upsertedCount", updateResult.getUpsertedId() == null ? new BsonInt32(0) : new BsonInt32(1));
    return toResult(resultDoc);
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument)

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