Search in sources :

Example 6 with BsonDbPointer

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

the class JsonReaderTest method testDBPointerWithNew.

@Test
public void testDBPointerWithNew() {
    String json = "new DBPointer(\"b\",\"5209296cd6c4e38cf96fffdc\")";
    bsonReader = new JsonReader(json);
    assertEquals(BsonType.DB_POINTER, bsonReader.readBsonType());
    BsonDbPointer dbPointer = bsonReader.readDBPointer();
    assertEquals("b", dbPointer.getNamespace());
    assertEquals(new ObjectId("5209296cd6c4e38cf96fffdc"), dbPointer.getId());
}
Also used : ObjectId(org.bson.types.ObjectId) BsonDbPointer(org.bson.BsonDbPointer) Test(org.junit.Test)

Example 7 with BsonDbPointer

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

the class JsonWriterTest method testDBPointer.

@Test
public void testDBPointer() {
    writer.writeStartDocument();
    writer.writeDBPointer("dbPointer", new BsonDbPointer("my.test", new ObjectId("4d0ce088e447ad08b4721a37")));
    writer.writeEndDocument();
    String expected = "{ \"dbPointer\" : { \"$ref\" : \"my.test\", \"$id\" : { \"$oid\" : \"4d0ce088e447ad08b4721a37\" } } }";
    assertEquals(expected, stringWriter.toString());
}
Also used : ObjectId(org.bson.types.ObjectId) BsonDbPointer(org.bson.BsonDbPointer) Test(org.junit.Test)

Example 8 with BsonDbPointer

use of org.bson.BsonDbPointer in project pinpoint by naver.

the class MongoDBITBase method createComplexDocument.

private Document createComplexDocument() {
    // insert Data
    BsonValue a = new BsonString("stest");
    BsonValue b = new BsonDouble(111);
    BsonValue c = new BsonBoolean(true);
    Document document = new Document().append("int32", new BsonInt32(12)).append("int64", new BsonInt64(77L)).append("bo\"olean", new BsonBoolean(true)).append("date", new BsonDateTime(new Date().getTime())).append("double", new BsonDouble(12.3)).append("string", new BsonString("pinpoint")).append("objectId", new BsonObjectId(new ObjectId())).append("code", new BsonJavaScript("int i = 10;")).append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))).append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")).append("symbol", new BsonSymbol("wow")).append("timestamp", new BsonTimestamp(0x12345678, 5)).append("undefined", new BsonUndefined()).append("binary1", new BsonBinary(new byte[] { (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20 })).append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[] { 1, 1, 1, 1, 1 })).append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))).append("document", new BsonDocument("a", new BsonInt32(77))).append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())).append("null", new BsonNull());
    return document;
}
Also used : BsonNull(org.bson.BsonNull) BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) BsonBinary(org.bson.BsonBinary) BsonDbPointer(org.bson.BsonDbPointer) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) BsonRegularExpression(org.bson.BsonRegularExpression) BsonBoolean(org.bson.BsonBoolean) BsonObjectId(org.bson.BsonObjectId) BsonJavaScript(org.bson.BsonJavaScript) Date(java.util.Date) BsonTimestamp(org.bson.BsonTimestamp) BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonSymbol(org.bson.BsonSymbol) BsonDocument(org.bson.BsonDocument) BsonDateTime(org.bson.BsonDateTime) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) BsonDouble(org.bson.BsonDouble) BsonJavaScriptWithScope(org.bson.BsonJavaScriptWithScope) BsonUndefined(org.bson.BsonUndefined) BsonValue(org.bson.BsonValue)

Aggregations

BsonDbPointer (org.bson.BsonDbPointer)8 ObjectId (org.bson.types.ObjectId)7 Test (org.junit.Test)4 Date (java.util.Date)2 BsonArray (org.bson.BsonArray)2 BsonBinary (org.bson.BsonBinary)2 BsonBoolean (org.bson.BsonBoolean)2 BsonDateTime (org.bson.BsonDateTime)2 BsonDocument (org.bson.BsonDocument)2 BsonDouble (org.bson.BsonDouble)2 BsonInt32 (org.bson.BsonInt32)2 BsonInt64 (org.bson.BsonInt64)2 BsonJavaScript (org.bson.BsonJavaScript)2 BsonJavaScriptWithScope (org.bson.BsonJavaScriptWithScope)2 BsonNull (org.bson.BsonNull)2 BsonObjectId (org.bson.BsonObjectId)2 BsonRegularExpression (org.bson.BsonRegularExpression)2 BsonString (org.bson.BsonString)2 BsonSymbol (org.bson.BsonSymbol)2 BsonTimestamp (org.bson.BsonTimestamp)2