Refine search
private static Bson createNearFilterDocument(final String fieldName, final double x, final double y, @Nullable final Double maxDistance, @Nullable final Double minDistance, final String operator) { BsonDocument nearFilter = new BsonDocument(operator, new BsonArray(Arrays.asList(new BsonDouble(x), new BsonDouble(y)))); if (maxDistance != null) { nearFilter.append("$maxDistance", new BsonDouble(maxDistance)); } if (minDistance != null) { nearFilter.append("$minDistance", new BsonDouble(minDistance)); } return new BsonDocument(fieldName, nearFilter); }
@Override protected double doReadDouble() { return currentValue.asDouble().getValue(); }
return clazz.cast(new Decimal128((Long) value)); } else if (value instanceof Double) { return clazz.cast(new BsonDouble((Double) value).decimal128Value()); } else if (value instanceof String) { return clazz.cast(Decimal128.parse((String) value));
private static SinkDocument buildSinkDocumentFlatStruct() { BsonDocument flatKey = new BsonDocument(); flatKey.put("_id", new BsonString("ABC-123")); flatKey.put("myBoolean",new BsonBoolean(true)); flatKey.put("myInt",new BsonInt32(42)); flatKey.put("myBytes",new BsonBinary(new byte[] {65,66,67})); flatKey.put("myArray", new BsonArray()); BsonDocument flatValue = new BsonDocument(); flatValue.put("_id", new BsonString("XYZ-789")); flatValue.put("myLong",new BsonInt64(42L)); flatValue.put("myDouble",new BsonDouble(23.23d)); flatValue.put("myString",new BsonString("BSON")); flatValue.put("myBytes",new BsonBinary(new byte[] {120,121,122})); flatValue.put("myArray", new BsonArray()); return new SinkDocument(flatKey,flatValue); }
/** * Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified * circle. * * @param fieldName the field name * @param x the x coordinate of the circle * @param y the y coordinate of the circle * @param radius the radius of the circle, as measured in the units used by the coordinate system * @return the filter * @mongodb.driver.manual reference/operator/query/geoWithin/ $geoWithin * @mongodb.driver.manual reference/operator/query/center/#op._S_center $center * @mongodb.server.release 2.4 * @since 3.1 */ public static Bson geoWithinCenter(final String fieldName, final double x, final double y, final double radius) { BsonDocument center = new BsonDocument("$center", new BsonArray(Arrays.<BsonValue>asList(new BsonArray(asList(new BsonDouble(x), new BsonDouble(y))), new BsonDouble(radius)))); return new OperatorFilter<BsonDocument>("$geoWithin", fieldName, center); }
EXPECTED_BSON_DOC_BYTES_1 = new BsonDocument() .append("_id", new BsonString("1234567890")) .append("myString", new BsonString("some foo bla text")) .append("myInt", new BsonInt32(42)) .append("myBoolean", new BsonBoolean(true)) .append("mySubDoc1", new BsonDocument("myString", new BsonString("hello json"))) .append("myArray1", new BsonArray(Arrays.asList( new BsonString("str_1"), new BsonString("str_2"), new BsonString("str_N"))) .append("myArray2", new BsonArray(Arrays.asList( new BsonDocument("k", new BsonString("a")).append("v", new BsonInt32(1)), new BsonDocument("k", new BsonString("b")).append("v", new BsonInt32(2)), EXPECTED_BSON_DOC_RAW_1 = EXPECTED_BSON_DOC_BYTES_1.clone(); EXPECTED_BSON_DOC_RAW_1.replace("myBytes",new BsonString("S2Fma2Egcm9ja3Mh")); EXPECTED_BSON_DOC_RAW_1.replace("myDate",new BsonInt64(1489705200000L)); EXPECTED_BSON_DOC_RAW_1.replace("myTimestamp",new BsonInt64(1489705200000L)); EXPECTED_BSON_DOC_RAW_1.replace("myTime",new BsonInt64(946724400000L)); EXPECTED_BSON_DOC_RAW_1.replace("myDecimal", new BsonDouble(12345.6789));
@BeforeEach public void setupDocumentsToRename() { keyDoc = new BsonDocument("fieldA",new BsonString("my field value")); keyDoc.put("f2",new BsonBoolean(true)); keyDoc.put("subDoc",new BsonDocument("fieldX",new BsonInt32(42))); keyDoc.put("my_field1",new BsonDocument("my_field2",new BsonString("testing rocks!"))); valueDoc = new BsonDocument("abc",new BsonString("my field value")); valueDoc.put("f2",new BsonBoolean(false)); valueDoc.put("subDoc",new BsonDocument("123",new BsonDouble(0.0))); valueDoc.put("foo.foo.foo",new BsonDocument(".blah..blah.",new BsonInt32(23))); }
/** * 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); }
colValue = keyvalueforStruct.getValue().asString().getValue().toString(); break; colValue = keyvalueforStruct.getValue().asDouble().getValue(); break; colValue = keyvalueforStruct.getValue().asInt64().getValue(); break; schema.field(keyvalueforStruct.getKey()).schema().field("scope").schema()); jsStruct.put("code", keyvalueforStruct.getValue().asJavaScriptWithScope().getCode()); BsonDocument jwsDoc = keyvalueforStruct.getValue().asJavaScriptWithScope().getScope().asDocument(); for (Entry<String, BsonValue> jwsDocKey : jwsDoc.entrySet()) { convertFieldValue(jwsDocKey, jsScopeStruct, schema.field(keyvalueforStruct.getKey()).schema()); BsonDocument docs = keyvalueforStruct.getValue().asDocument(); for (Entry<String, BsonValue> doc : docs.entrySet()) { convertFieldValue(doc, documentStruct, documentSchema); list.add(temp); } else if (arrValue.getBsonType() == BsonType.DOUBLE && valueType == BsonType.DOUBLE) { double temp = arrValue.asDouble().getValue(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.BINARY && valueType == BsonType.BINARY) {
value.asDocument().size()); for (java.util.Map.Entry<String, BsonValue> entry : value.asDocument().entrySet()) { map.put(entry.getKey(), translatePrivate(entry.getValue())); return PrimitiveBsonDouble.newInstance(value.asDouble().getValue()); case BOOLEAN: if (value.asBoolean().getValue()) { return PrimitiveBsonInt32.newInstance(value.asInt32().getValue()); case INT64: return PrimitiveBsonInt64.newInstance(value.asInt64().getValue()); case JAVASCRIPT: { return new DefaultBsonJavaScript(value.asJavaScript().getCode()); return new StringBsonString(value.asString().getValue()); case TIMESTAMP: { BsonTimestamp casted = value.asTimestamp();
return value.asInt32().getValue(); case INT64: return value.asInt64().getValue(); case STRING: return value.asString().getValue(); case DECIMAL128: return value.asDecimal128().doubleValue(); case DOUBLE: return value.asDouble().getValue(); case BOOLEAN: return value.asBoolean().getValue(); return value.asSymbol().getSymbol(); case ARRAY: return value.asArray().toArray(); case DOCUMENT: return Document.parse(value.asDocument().toJson()); default: return value;
private MongoVersion calculateVersion() { Document buildInfo = driverClient .getDatabase("admin") .runCommand(new BsonDocument("buildInfo", new BsonDouble(1.0))); String versionString = buildInfo.getString("version"); return MongoVersion.fromMongoString(versionString); }
TypeAdapters.JSON_ELEMENT.write(new BsonWriter(new BsonDocumentWriter(doc)), obj); check(doc.keySet()).notEmpty(); check(doc.get("boolean").getBsonType()).is(BsonType.BOOLEAN); check(doc.get("boolean").asBoolean()); check(doc.get("int32").getBsonType()).is(BsonType.INT32); check(doc.get("int32").asInt32().getValue()).is(32); check(doc.get("int64").getBsonType()).is(BsonType.INT64); check(doc.get("int64").asInt64().getValue()).is(64L); check(doc.get("double").getBsonType()).is(BsonType.DOUBLE); check(doc.get("double").asDouble().getValue()).is(42.42D); check(doc.get("string").getBsonType()).is(BsonType.STRING); check(doc.get("string").asString().getValue()).is("foo"); check(doc.get("null").getBsonType()).is(BsonType.NULL); check(doc.get("null").isNull());
@Override protected BsonArray toCoordinates() { BsonArray coordinates = new BsonArray(); coordinates.add( new BsonDouble( longitude ) ); coordinates.add( new BsonDouble( latitude ) ); return coordinates; }
if (options.containsKey("name") && options.get("name").isString()) { ret.name(options.get("name").asString().getValue()); && options.get("default_language").isString()) { ret.defaultLanguage(options.get("default_language") .asString().getValue()); && options.get("language_override").isString()) { ret.languageOverride(options.get("language_override") .asString().getValue()); && options.get("min").isDouble()) { ret.min(options.get("min") .asDouble().getValue()); && options.get("max").isDouble()) { ret.max(options.get("max") .asDouble().getValue()); && options.get("bucketSize").isDouble()) { ret.bucketSize(options.get("bucketSize") .asDouble().getValue());
private BsonValue constructValue(Object value) { if (value == null) { return BsonNull.VALUE; } else if (value instanceof Double) { return new BsonDouble((Double) value); } else if (value instanceof String) { return new BsonString((String) value); } else if (value instanceof ObjectId) { return new BsonObjectId((ObjectId) value); } else if (value instanceof Integer) { return new BsonInt32((Integer) value); } else if (value instanceof Long) { return new BsonInt64((Long) value); } else if (value instanceof Decimal128) { return new BsonDecimal128((Decimal128) value); } throw new IllegalArgumentException("Unsupported ID type: " + value.getClass()); }
uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/") .concat(((BsonString) docId).getValue()); } else if (docId instanceof BsonBoolean) { uri = URLUtils.removeTrailingSlashes(parentUrl) uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/") .concat("" + ((BsonNumber) docId).asInt64().getValue()); } else if (docId instanceof BsonDouble) { uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/") .concat("" + ((BsonDouble) docId).asDouble().getValue()); } else if (docId instanceof BsonNull) { uri = URLUtils.removeTrailingSlashes(parentUrl)
@Test public void basicNumbers() throws Exception { JsonObject obj = new JsonObject(); obj.addProperty("boolean", true); obj.addProperty("byte", (byte) 1); obj.addProperty("short", (short) 4); obj.addProperty("int", Integer.MAX_VALUE); obj.addProperty("long", Long.MAX_VALUE); obj.addProperty("float", 55F); obj.addProperty("double", 128D); BsonDocument doc = Jsons.toBson(obj); check(doc.get("boolean").getBsonType()).is(BsonType.BOOLEAN); check(doc.get("boolean").asBoolean()); check(doc.get("byte").getBsonType()).is(BsonType.INT32); check(doc.get("byte").asInt32().getValue()).is(1); check(doc.get("short").getBsonType()).is(BsonType.INT32); check(doc.get("short").asInt32().getValue()).is(4); check(doc.get("int").getBsonType()).is(BsonType.INT32); check(doc.get("int").asInt32().getValue()).is(Integer.MAX_VALUE); check(doc.get("long").getBsonType()).is(BsonType.INT64); check(doc.get("long").asInt64().getValue()).is(Long.MAX_VALUE); check(doc.get("float").getBsonType()).is(BsonType.DOUBLE); check(doc.get("float").asDouble().getValue()).is(55D); check(doc.get("double").getBsonType()).is(BsonType.DOUBLE); check(doc.get("double").asDouble().getValue()).is(128D); }
@Override public BsonDouble decode(final BsonReader reader, final DecoderContext decoderContext) { return new BsonDouble(reader.readDouble()); }