Search in sources :

Example 26 with BsonObjectId

use of org.bson.BsonObjectId in project spring-data-mongodb by spring-projects.

the class GridFsTemplateIntegrationTests method marshalsComplexMetadata.

// DATAMONGO-6
@Test
public void marshalsComplexMetadata() throws IOException {
    Metadata metadata = new Metadata();
    metadata.version = "1.0";
    ObjectId reference = operations.store(resource.getInputStream(), "foo.xml", metadata);
    List<com.mongodb.client.gridfs.model.GridFSFile> files = new ArrayList<com.mongodb.client.gridfs.model.GridFSFile>();
    GridFSFindIterable result = operations.find(query(whereFilename().is("foo.xml")));
    result.into(files);
    assertThat(files.size()).isEqualTo(1);
    assertThat(((BsonObjectId) files.get(0).getId()).getValue()).isEqualTo(reference);
}
Also used : BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) GridFSFile(com.mongodb.client.gridfs.model.GridFSFile) ArrayList(java.util.ArrayList) GridFSFindIterable(com.mongodb.client.gridfs.GridFSFindIterable) BsonObjectId(org.bson.BsonObjectId) Test(org.junit.Test)

Example 27 with BsonObjectId

use of org.bson.BsonObjectId 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

BsonObjectId (org.bson.BsonObjectId)27 ObjectId (org.bson.types.ObjectId)23 Test (org.junit.Test)19 GridFSFile (com.mongodb.client.gridfs.model.GridFSFile)12 ArrayList (java.util.ArrayList)11 Document (org.bson.Document)9 GridFSFindIterable (com.mongodb.client.gridfs.GridFSFindIterable)8 BsonDocument (org.bson.BsonDocument)8 List (java.util.List)7 MongoGridFSException (com.mongodb.MongoGridFSException)6 BsonArray (org.bson.BsonArray)6 BsonString (org.bson.BsonString)6 BsonValue (org.bson.BsonValue)6 Date (java.util.Date)5 IOException (java.io.IOException)4 Assertions (org.assertj.core.api.Assertions)4 Before (org.junit.Before)4 RunWith (org.junit.runner.RunWith)4 Autowired (org.springframework.beans.factory.annotation.Autowired)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3