Example usage for com.mongodb CommandResult getInt

List of usage examples for com.mongodb CommandResult getInt

Introduction

In this page you can find the example usage for com.mongodb CommandResult getInt.

Prototype

public int getInt(final String key, final int def) 

Source Link

Document

Returns the value of a field as an int .

Usage

From source file:de.flapdoodle.mongoom.datastore.Errors.java

License:Apache License

public static void checkError(DB db, Operation operation) {
    CommandResult lastError = db.getLastError();
    if (lastError.get("err") != null) {
        _logger.severe(lastError.get("err").toString());
        // throw lastError.getException();
        throw new ObjectMapperException(lastError.get("err").toString());
    }/*from   w  w  w  .  j  a v  a2 s .  com*/
    switch (operation) {
    case Update:
        if (lastError.getInt("updatedExisting", 0) == 0) {
            throw new UpdateFailedException();
        }
        break;

    case Delete:
        if (lastError.getInt("n", 0) == 0) {
            throw new UpdateFailedException();
        }
        break;
    }

}

From source file:de.otto.mongodb.profiler.op.DefaultOpProfiler.java

License:Apache License

@Override
public ProfilingLevel getProfilingLevel() {
    final CommandResult result = db.command(BasicDBObjectBuilder.start("profile", -1).get());
    result.throwOnError();/*from  w  w w  .ja  v a 2 s .  co  m*/
    return ProfilingLevel.forValue(result.getInt("was", Integer.MIN_VALUE));
}