Example usage for com.mongodb DBCollection findOne

List of usage examples for com.mongodb DBCollection findOne

Introduction

In this page you can find the example usage for com.mongodb DBCollection findOne.

Prototype

@Nullable
public DBObject findOne(@Nullable final DBObject query, final DBCollectionFindOptions findOptions) 

Source Link

Document

Get a single document from collection.

Usage

From source file:rapture.sheet.mongodb.MongoMetaSheetStore.java

License:Open Source License

public RaptureSheetScript getSheetScript(String name, String scriptName) {
    DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName);
    BasicDBObject query = new BasicDBObject();
    query.append(TYPE, SCRIPT);// ww  w.j  av  a2 s  .c  om
    query.append(KEY, name);
    query.append(NAME, scriptName);
    BasicDBObject values = new BasicDBObject();
    values.append(VALUE, 1);
    BasicDBObject value = (BasicDBObject) collection.findOne(query, values);
    if (value != null) {
        String content = value.getString(VALUE);
        RaptureSheetScript script = JacksonUtil.objectFromJson(content, RaptureSheetScript.class);
        return script;
    }
    return null;
}

From source file:rapture.sheet.mongodb.MongoMetaSheetStore.java

License:Open Source License

public RaptureSheetRange getSheetNamedSelection(String name, String rangeName) {
    DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName);
    BasicDBObject query = new BasicDBObject();
    query.append(TYPE, RANGE);/*from w w  w .  j a va2s.  co  m*/
    query.append(KEY, name);
    query.append(NAME, rangeName);
    BasicDBObject values = new BasicDBObject();
    values.append(VALUE, 1);
    BasicDBObject value = (BasicDBObject) collection.findOne(query, values);
    if (value != null) {
        String content = value.getString(VALUE);
        RaptureSheetRange range = JacksonUtil.objectFromJson(content, RaptureSheetRange.class);
        return range;
    }
    return null;
}