Example usage for com.mongodb.util JSON parse

List of usage examples for com.mongodb.util JSON parse

Introduction

In this page you can find the example usage for com.mongodb.util JSON parse.

Prototype

public static Object parse(final String jsonString) 

Source Link

Document

Parses a JSON string and returns a corresponding Java object.

Usage

From source file:org.eclipse.tracecompass.totalads.dbms.MongoDBMS.java

License:Open Source License

@Override
public void updateFieldsInExistingDocUsingJSON(String database, JsonObject keytoSearch,
        JsonObject jsonObjectToUpdate, String collection) throws TotalADSDBMSException {

    DB db = mongoClient.getDB(database);
    DBCollection col = db.getCollection(collection);

    BasicDBObject query = (BasicDBObject) JSON.parse(keytoSearch.toString());
    // new BasicDBObject();
    // query.put("name", "MongoDB");

    BasicDBObject newDocument = (BasicDBObject) JSON.parse(jsonObjectToUpdate.toString());
    // newDocument.put("name", "MongoDB-updated");

    BasicDBObject updateObj = new BasicDBObject();
    updateObj.put("$set", newDocument); //$NON-NLS-1$

    col.update(query, updateObj);/*from   w w  w  .  j ava 2 s . c  o  m*/

}

From source file:org.eclipselabs.mongoemf.query.mongodb.NativeQueryEngine.java

License:Open Source License

@Override
public MongoQuery buildDBObjectQuery(URI uri) {
    DBObject query = (DBObject) JSON.parse(URI.decode(uri.query()));

    MongoQuery mongoQuery = ModelFactory.eINSTANCE.createMongoQuery();
    mongoQuery.setFilter((DBObject) query.get("filter"));
    mongoQuery.setProjection((DBObject) query.get("projection"));
    mongoQuery.setSort((DBObject) query.get("sort"));
    mongoQuery.setLimit((Integer) query.get("limit"));

    return mongoQuery;
}