Search in sources :

Example 1 with BsonInt32

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

the class InternalStreamConnectionInitializer method initializeConnectionDescription.

private ConnectionDescription initializeConnectionDescription(final InternalConnection internalConnection) {
    BsonDocument isMasterResult = executeCommand("admin", createIsMasterCommand(), internalConnection);
    BsonDocument buildInfoResult = executeCommand("admin", new BsonDocument("buildinfo", new BsonInt32(1)), internalConnection);
    return createConnectionDescription(internalConnection.getDescription().getConnectionId(), isMasterResult, buildInfoResult);
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument)

Example 2 with BsonInt32

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

the class InternalStreamConnectionInitializer method initializeConnectionDescriptionAsync.

private void initializeConnectionDescriptionAsync(final InternalConnection internalConnection, final SingleResultCallback<ConnectionDescription> callback) {
    executeCommandAsync("admin", createIsMasterCommand(), internalConnection, new SingleResultCallback<BsonDocument>() {

        @Override
        public void onResult(final BsonDocument isMasterResult, final Throwable t) {
            if (t != null) {
                callback.onResult(null, t);
            } else {
                executeCommandAsync("admin", new BsonDocument("buildinfo", new BsonInt32(1)), internalConnection, new SingleResultCallback<BsonDocument>() {

                    @Override
                    public void onResult(final BsonDocument buildInfoResult, final Throwable t) {
                        if (t != null) {
                            callback.onResult(null, t);
                        } else {
                            ConnectionId connectionId = internalConnection.getDescription().getConnectionId();
                            callback.onResult(createConnectionDescription(connectionId, isMasterResult, buildInfoResult), null);
                        }
                    }
                });
            }
        }
    });
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) SingleResultCallback(com.mongodb.async.SingleResultCallback)

Example 3 with BsonInt32

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

the class MapReduceWithInlineResultsOperation method getCommand.

private BsonDocument getCommand() {
    BsonDocument commandDocument = new BsonDocument("mapreduce", new BsonString(namespace.getCollectionName())).append("map", getMapFunction()).append("reduce", getReduceFunction()).append("out", new BsonDocument("inline", new BsonInt32(1))).append("query", asValueOrNull(getFilter())).append("sort", asValueOrNull(getSort())).append("finalize", asValueOrNull(getFinalizeFunction())).append("scope", asValueOrNull(getScope())).append("verbose", BsonBoolean.valueOf(isVerbose()));
    putIfNotZero(commandDocument, "limit", getLimit());
    putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS));
    putIfTrue(commandDocument, "jsMode", isJsMode());
    if (!readConcern.isServerDefault()) {
        commandDocument.put("readConcern", readConcern.asDocument());
    }
    if (collation != null) {
        commandDocument.put("collation", collation.asDocument());
    }
    return commandDocument;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 4 with BsonInt32

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

the class QueryBatchCursor method asGetMoreCommandDocument.

private BsonDocument asGetMoreCommandDocument() {
    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 5 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)

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