Example usage for com.mongodb DBObject put

List of usage examples for com.mongodb DBObject put

Introduction

In this page you can find the example usage for com.mongodb DBObject put.

Prototype

Object put(String key, Object v);

Source Link

Document

Sets a name/value pair in this object.

Usage

From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java

License:Open Source License

/**
 * collection validate/*from  w  w  w.  j a v a  2s .  com*/
 * 
 * @param userDB
 * @param collName
 * @param isFull
 * @return
 * @throws Exception
 */
public static BasicDBObject collValidate(UserDBDAO userDB, String collName, boolean isFull) throws Exception {

    DBObject queryObj = new BasicDBObject("validate", collName);
    queryObj.put("full", isFull);
    CommandResult cr = findDB(userDB).command(queryObj);

    if (!cr.ok())
        throw cr.getException();
    if (logger.isDebugEnabled())
        logger.debug("[compact] complements" + cr.toString());

    return (BasicDBObject) cr;
}

From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java

License:Open Source License

/**
 * collection compact/*  www .ja v  a2  s .  c  o  m*/
 * 
 * @param userDB
 * @param colName
 * @param force
 * @param paddingFactor
 * @param paddingBytes
 * @return
 * @throws Exception
 */
public static String collCompact(UserDBDAO userDB, String colName, boolean isForct, int paddingFactor,
        int paddingBytes) throws Exception {
    DB mongoDB = findDB(userDB);

    DBObject queryObj = new BasicDBObject("compact", colName);
    if (paddingFactor > 0)
        queryObj.put("paddingFactor", paddingFactor);
    if (paddingBytes > 0)
        queryObj.put("paddingBytes", paddingBytes);

    CommandResult cr = mongoDB.command(queryObj);

    if (!cr.ok())
        throw cr.getException();
    if (logger.isDebugEnabled())
        logger.debug("[compact] complements" + cr.toString());

    return cr.toString();
}

From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java

License:Open Source License

/**
 * gridFS//from  w ww  .  j  a v  a 2  s.  co  m
 * 
 * @param userDB
 * @param strBucket
 * @param strFileName
 * @param intSkip
 * @param intLimit
 * @return
 * @throws Exception
 */
public static DBCursor getGridFS(UserDBDAO userDB, String strBucket, String strFileName, int intSkip,
        int intLimit) throws Exception {
    DB mongoDb = findDB(userDB);
    GridFS gridFs = null;

    if ("".equals(strBucket))
        gridFs = new GridFS(mongoDb);
    else
        gridFs = new GridFS(mongoDb, strBucket);

    if ("".equals(strFileName)) {
        return gridFs.getFileList().skip(intSkip).limit(intLimit);
    } else {
        DBObject queryObj = new BasicDBObject();
        Pattern regex = Pattern.compile(".*" + strFileName + "*");
        queryObj.put("filename", regex);

        return gridFs.getFileList(queryObj).skip(intSkip).limit(intLimit);
    }
}

From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java

License:Open Source License

/**
 * GridFS chunck detail information//from   ww w. j  av a  2 s.c o m
 * 
 * @param userDB
 * @param objectId
 * @return
 * @throws Exception
 */
public static DBCursor getGridFSChunckDetail(UserDBDAO userDB, String searchChunkName, String objectId)
        throws Exception {
    DBCollection col = findCollection(userDB, searchChunkName);

    // 
    DBObject queryObj = new BasicDBObject();
    queryObj.put("files_id", new ObjectId(objectId));

    // field
    DBObject fieldObj = new BasicDBObject();
    fieldObj.put("files_id", 1);
    fieldObj.put("n", 1);

    return col.find(queryObj, fieldObj);
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestReferenceCollection.java

License:Open Source License

public static void createRef1Collection(DB db, Object objId) {
    DBObject colInformation = (DBObject) JSON.parse("{capped:true, size:100000}");
    DBCollection ref2Coll = db.getCollection(REF_2);
    if (ref2Coll != null)
        ref2Coll.drop();/* w  w  w. j  a va2 s . c o m*/
    ref2Coll = db.createCollection(REF_2, colInformation);

    BasicDBObject insertObj = new BasicDBObject();
    insertObj.put(REF_1 + "_id", objId);

    DBObject addField = new BasicDBObject();
    addField.put("name", "Reference id");

    insertObj.putAll(addField);

    //      DBObject dbObjRef2 = (DBObject) JSON.parse("{'ref1_id': 50f9437cf023f820730a3b42,  {'names': {'First': 'Gonza', 'Last': 'Vieira'}}}");
    ref2Coll.insert(insertObj);
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestServerSideJavascript.java

License:Open Source License

/**
 * ?? /*  www. java 2s.  c o m*/
 *  
 * @param db
 * @param jsName
 * @return
 */
private static String findServerSideJavaScript(DB db, String jsName) {
    DBObject findDbObject = new BasicDBObject();
    findDbObject.put("_id", jsName);

    DBCursor dbCursor = db.getCollection("system.js").find(findDbObject);
    DBObject dbObject = dbCursor.next();
    return dbObject.get("value").toString();
}

From source file:com.harpatec.examples.converter.DateTimeWriteConverter.java

License:Apache License

@Override
public DBObject convert(DateTime source) {
    DBObject dbo = new BasicDBObject();
    dbo.put("millis", source.getMillis());
    dbo.put("formatted", source.toDateTime(DateTimeZone.UTC).toString());
    return dbo;//from  w  ww. ja va  2s.  c  o m
}

From source file:com.health.smart.ejb.MongoEJB.java

@Schedule(minute = "*/15", hour = "*", persistent = false)
public void checkMeasurement() throws Exception {
    BasicDBObject gt60 = new BasicDBObject("$gte", 160);
    BasicDBObject alertExists = new BasicDBObject("$exists", false);
    BasicDBObject doc = new BasicDBObject("bph", gt60).append("alerted", alertExists);
    List<DBObject> result = MongoC.findObject("measurement", doc);

    for (DBObject obj : result) {
        int pid = (Integer) obj.get("patientId");
        double value = (Double) obj.get("bph");
        int success = ejb.sendMsg(pid,
                String.format("Systolic level too high (%s)!\r\n Please make appointment ASAP!",
                        NumberFormat.getInstance().format(value)));
        if (success > 0) {
            obj.put("alerted", true);
            BasicDBObject filter = new BasicDBObject();
            filter.append("_id", obj.get("_id"));
            MongoC.update("measurement", filter, obj);
        }/*w  ww . j a  v  a2  s .  c om*/
    }
}

From source file:com.ibm.ws.lars.rest.PersistenceBean.java

License:Apache License

private static void convertObjectIdToHexString(DBObject obj) {
    Object objectIdObject = obj.get(ID);
    if ((objectIdObject != null) && (objectIdObject instanceof ObjectId)) {
        ObjectId objId = (ObjectId) objectIdObject;
        String hex = objId.toStringMongod();
        obj.put(ID, hex);
    }//ww w .  ja  va 2 s.co m
}

From source file:com.ibm.ws.lars.rest.PersistenceBean.java

License:Apache License

private static void convertHexIdToObjectId(DBObject obj) {
    Object idObject = obj.get(ID);
    if ((idObject != null) && (idObject instanceof String)) {
        String hex = (String) idObject;
        obj.put(ID, new ObjectId(hex));
    }//w w w.  j  a  va 2  s  . c  o  m
}