Search in sources :

Example 1 with BsonDouble

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

the class GetMoreProtocol method asGetMoreCommandResponseDocument.

private BsonDocument asGetMoreCommandResponseDocument(final QueryResult<T> queryResult, final ResponseBuffers responseBuffers) {
    List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
    if (responseBuffers.getReplyHeader().getNumberReturned() != 0) {
        responseBuffers.getBodyByteBuffer().position(0);
        rawResultDocuments = ByteBufBsonDocument.create(responseBuffers);
    }
    BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("nextBatch", new BsonArray(rawResultDocuments));
    return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) BsonDouble(org.bson.BsonDouble)

Example 2 with BsonDouble

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

the class CommandResultTest method shouldBeOkWhenOkFieldIsOne.

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

Example 3 with BsonDouble

use of org.bson.BsonDouble in project drill by apache.

the class TestBsonRecordReader method testDoubleType.

@Test
public void testDoubleType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    bsonDoc.append("doubleKey", new BsonDouble(12.35));
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    assertEquals(12.35d, mapReader.reader("doubleKey").readDouble().doubleValue(), 0.00001);
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonDouble(org.bson.BsonDouble) BsonDocumentReader(org.bson.BsonDocumentReader) Test(org.junit.Test)

Example 4 with BsonDouble

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

the class Filters method geoWithinPolygon.

/**
     * Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified
     * polygon.
     *
     * @param fieldName the field name
     * @param points    a list of pairs of x, y coordinates.  Any extra dimensions are ignored
     * @return the filter
     * @mongodb.driver.manual reference/operator/query/geoWithin/ $geoWithin
     * @mongodb.driver.manual reference/operator/query/polygon/#op._S_polygon $polygon
     * @mongodb.server.release 2.4
     * @since 3.1
     */
public static Bson geoWithinPolygon(final String fieldName, final List<List<Double>> points) {
    BsonArray pointsArray = new BsonArray();
    for (List<Double> point : points) {
        pointsArray.add(new BsonArray(asList(new BsonDouble(point.get(0)), new BsonDouble(point.get(1)))));
    }
    BsonDocument polygon = new BsonDocument("$polygon", pointsArray);
    return new OperatorFilter<BsonDocument>("$geoWithin", fieldName, polygon);
}
Also used : BsonDocument(org.bson.BsonDocument) BsonArray(org.bson.BsonArray) BsonDouble(org.bson.BsonDouble) BsonDouble(org.bson.BsonDouble)

Example 5 with BsonDouble

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

the class QueryProtocol method asFindCommandResponseDocument.

private BsonDocument asFindCommandResponseDocument(final ResponseBuffers responseBuffers, final QueryResult<T> queryResult, final boolean isExplain) {
    List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
    if (responseBuffers.getReplyHeader().getNumberReturned() > 0) {
        responseBuffers.getBodyByteBuffer().position(0);
        rawResultDocuments = ByteBufBsonDocument.create(responseBuffers);
    }
    if (isExplain) {
        BsonDocument explainCommandResponseDocument = new BsonDocument("ok", new BsonDouble(1));
        explainCommandResponseDocument.putAll(rawResultDocuments.get(0));
        return explainCommandResponseDocument;
    } else {
        BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("firstBatch", new BsonArray(rawResultDocuments));
        return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
    }
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) BsonDouble(org.bson.BsonDouble)

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