Search in sources :

Example 6 with BsonDouble

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

the class CreateIndexesOperation method getIndex.

private BsonDocument getIndex(final IndexRequest request) {
    BsonDocument index = new BsonDocument();
    index.append("key", request.getKeys());
    index.append("name", new BsonString(request.getName() != null ? request.getName() : generateIndexName(request.getKeys())));
    index.append("ns", new BsonString(namespace.getFullName()));
    if (request.isBackground()) {
        index.append("background", BsonBoolean.TRUE);
    }
    if (request.isUnique()) {
        index.append("unique", BsonBoolean.TRUE);
    }
    if (request.isSparse()) {
        index.append("sparse", BsonBoolean.TRUE);
    }
    if (request.getExpireAfter(TimeUnit.SECONDS) != null) {
        index.append("expireAfterSeconds", new BsonInt64(request.getExpireAfter(TimeUnit.SECONDS)));
    }
    if (request.getVersion() != null) {
        index.append("v", new BsonInt32(request.getVersion()));
    }
    if (request.getWeights() != null) {
        index.append("weights", request.getWeights());
    }
    if (request.getDefaultLanguage() != null) {
        index.append("default_language", new BsonString(request.getDefaultLanguage()));
    }
    if (request.getLanguageOverride() != null) {
        index.append("language_override", new BsonString(request.getLanguageOverride()));
    }
    if (request.getTextVersion() != null) {
        index.append("textIndexVersion", new BsonInt32(request.getTextVersion()));
    }
    if (request.getSphereVersion() != null) {
        index.append("2dsphereIndexVersion", new BsonInt32(request.getSphereVersion()));
    }
    if (request.getBits() != null) {
        index.append("bits", new BsonInt32(request.getBits()));
    }
    if (request.getMin() != null) {
        index.append("min", new BsonDouble(request.getMin()));
    }
    if (request.getMax() != null) {
        index.append("max", new BsonDouble(request.getMax()));
    }
    if (request.getBucketSize() != null) {
        index.append("bucketSize", new BsonDouble(request.getBucketSize()));
    }
    if (request.getDropDups()) {
        index.append("dropDups", BsonBoolean.TRUE);
    }
    if (request.getStorageEngine() != null) {
        index.append("storageEngine", request.getStorageEngine());
    }
    if (request.getPartialFilterExpression() != null) {
        index.append("partialFilterExpression", request.getPartialFilterExpression());
    }
    if (request.getCollation() != null) {
        index.append("collation", request.getCollation().asDocument());
    }
    return index;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonDouble(org.bson.BsonDouble)

Example 7 with BsonDouble

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

the class CommandMonitoringTest method massageActualCommandSucceededEvent.

private CommandSucceededEvent massageActualCommandSucceededEvent(final CommandSucceededEvent actual) {
    BsonDocument response = getWritableCloneOfCommand(actual.getResponse());
    // massage numbers that are the wrong BSON type
    response.put("ok", new BsonDouble(response.getNumber("ok").doubleValue()));
    if (response.containsKey("n")) {
        response.put("n", new BsonInt32(response.getNumber("n").intValue()));
    }
    if (actual.getCommandName().equals("find") || actual.getCommandName().equals("getMore")) {
        if (response.containsKey("cursor")) {
            if (response.getDocument("cursor").containsKey("id") && !response.getDocument("cursor").getInt64("id").equals(new BsonInt64(0))) {
                response.getDocument("cursor").put("id", new BsonInt64(42));
            }
        }
    } else if (actual.getCommandName().equals("killCursors")) {
        response.getArray("cursorsUnknown").set(0, new BsonInt64(42));
    } else if (isWriteCommand(actual.getCommandName())) {
        if (response.containsKey("writeErrors")) {
            for (Iterator<BsonValue> iter = response.getArray("writeErrors").iterator(); iter.hasNext(); ) {
                BsonDocument cur = iter.next().asDocument();
                cur.put("code", new BsonInt32(42));
                cur.put("errmsg", new BsonString(""));
            }
        }
        if (actual.getCommandName().equals("update")) {
            response.remove("nModified");
        }
    }
    return new CommandSucceededEvent(actual.getRequestId(), actual.getConnectionDescription(), actual.getCommandName(), response, actual.getElapsedTime(TimeUnit.NANOSECONDS));
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) CommandSucceededEvent(com.mongodb.event.CommandSucceededEvent) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonDouble(org.bson.BsonDouble) BsonValue(org.bson.BsonValue)

Example 8 with BsonDouble

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

the class CommandResultTest method shouldNotBeOkWhenOkFieldIsZero.

@Test
public void shouldNotBeOkWhenOkFieldIsZero() throws UnknownHostException {
    CommandResult commandResult = new CommandResult(new BsonDocument("ok", new BsonDouble(0.0)));
    assertFalse(commandResult.ok());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDouble(org.bson.BsonDouble) Test(org.junit.Test)

Aggregations

BsonDocument (org.bson.BsonDocument)8 BsonDouble (org.bson.BsonDouble)8 BsonInt64 (org.bson.BsonInt64)4 BsonString (org.bson.BsonString)4 BsonArray (org.bson.BsonArray)3 Test (org.junit.Test)3 BsonInt32 (org.bson.BsonInt32)2 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)1 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)1 BsonDocumentReader (org.bson.BsonDocumentReader)1 BsonValue (org.bson.BsonValue)1