Search in sources :

Example 66 with DBObject

use of com.mongodb.DBObject in project morphia by mongodb.

the class Converters method toDBObject.

/**
     * Converts an entity to a DBObject
     *
     * @param containingObject The object to convert
     * @param mf               the MappedField to extract
     * @param dbObj            the DBObject to populate
     * @param opts             the options to apply
     */
public void toDBObject(final Object containingObject, final MappedField mf, final DBObject dbObj, final MapperOptions opts) {
    final Object fieldValue = mf.getFieldValue(containingObject);
    final TypeConverter enc = getEncoder(fieldValue, mf);
    final Object encoded = enc.encode(fieldValue, mf);
    if (encoded != null || opts.isStoreNulls()) {
        dbObj.put(mf.getNameToStore(), encoded);
    }
}
Also used : DBObject(com.mongodb.DBObject)

Example 67 with DBObject

use of com.mongodb.DBObject in project mongo-java-driver by mongodb.

the class GridFSTest method testRemoveWhenQueryIsNull.

@Test(expected = IllegalArgumentException.class)
public void testRemoveWhenQueryIsNull() {
    DBObject dbObjectQuery = null;
    gridFS.remove(dbObjectQuery);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 68 with DBObject

use of com.mongodb.DBObject in project mongo-java-driver by mongodb.

the class JSONTest method testBin.

@Test
public void testBin() {
    byte[] b = { 'a', 'b', 0, 'd' };
    DBObject obj = BasicDBObjectBuilder.start().add("b", b).get();
    assertEquals("{ \"b\" : <Binary Data>}", JSON.serialize(obj));
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 69 with DBObject

use of com.mongodb.DBObject in project mongo-java-driver by mongodb.

the class JSONTest method testNumbers2.

@Test
public void testNumbers2() {
    DBObject x = new BasicDBObject("x", 123);
    assertEquals(JSON.parse(x.toString()), x);
    x = new BasicDBObject("x", 123123123123L);
    assertEquals(JSON.parse(x.toString()), x);
    x = new BasicDBObject("x", 123123123);
    assertEquals(JSON.parse(x.toString()), x);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 70 with DBObject

use of com.mongodb.DBObject in project mongo-java-driver by mongodb.

the class JSONTest method testEscape1.

@Test
public void testEscape1() {
    String raw = "a\nb";
    DBObject x = new BasicDBObject("x", raw);
    assertEquals("\"a\\nb\"", JSON.serialize(raw));
    assertEquals(x, JSON.parse(x.toString()));
    assertEquals(raw, ((DBObject) JSON.parse(x.toString())).get("x"));
    x = new BasicDBObject("x", "a\nb\bc\td\re");
    assertEquals(x, JSON.parse(x.toString()));
    String thingy = "va\"lue";
    x = new BasicDBObject("name", thingy);
    x = (DBObject) JSON.parse(x.toString());
    assertEquals(thingy, x.get("name"));
    thingy = "va\\lue";
    x = new BasicDBObject("name", thingy);
    x = (DBObject) JSON.parse(x.toString());
    assertEquals(thingy, x.get("name"));
    assertEquals("va/lue", JSON.parse("\"va\\/lue\""));
    assertEquals("value", JSON.parse("\"va\\lue\""));
    assertEquals("va\\lue", JSON.parse("\"va\\\\lue\""));
    escapeChar("\t");
    escapeChar("\b");
    escapeChar("\n");
    escapeChar("\r");
    escapeChar("\'");
    escapeChar("\"");
    escapeChar("\\");
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

DBObject (com.mongodb.DBObject)646 BasicDBObject (com.mongodb.BasicDBObject)445 Test (org.junit.Test)267 YearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest)95 DBCollection (com.mongodb.DBCollection)84 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)79 ApiOperation (io.swagger.annotations.ApiOperation)71 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)70 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)63 CustomProjectionOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation)53 ArrayList (java.util.ArrayList)44 DBCursor (com.mongodb.DBCursor)42 HashMap (java.util.HashMap)40 List (java.util.List)35 ObjectId (org.bson.types.ObjectId)30 BasicDBList (com.mongodb.BasicDBList)29 Map (java.util.Map)28 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)20 CustomGroupingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation)20 BSONObject (org.bson.BSONObject)19