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));
}
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());
}
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);
}
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);
}
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));
}
}
Aggregations