Example usage for com.mongodb DBCursor skip

List of usage examples for com.mongodb DBCursor skip

Introduction

In this page you can find the example usage for com.mongodb DBCursor skip.

Prototype

public DBCursor skip(final int numberOfElements) 

Source Link

Document

Discards a given number of elements at the beginning of the cursor.

Usage

From source file:org.vertx.mods.MongoPersistor.java

License:Apache License

private void doFind(Message<JsonObject> message) {
    String collection = getMandatoryString("collection", message);
    if (collection == null) {
        return;//from w  w  w.j  a  v a 2s .  c o m
    }
    Integer limit = (Integer) message.body.getNumber("limit");
    if (limit == null) {
        limit = -1;
    }
    Integer skip = (Integer) message.body.getNumber("skip");
    if (skip == null) {
        skip = -1;
    }

    Integer batchSize = (Integer) message.body.getNumber("batch_size");
    if (batchSize == null) {
        batchSize = 100;
    }
    JsonObject matcher = getMandatoryObject("matcher", message);
    if (matcher == null) {
        return;
    }
    JsonObject keys = message.body.getObject("keys");

    Object sort = message.body.getField("sort");
    DBCollection coll = db.getCollection(collection);
    DBCursor cursor = (keys == null) ? coll.find(jsonToDBObject(matcher))
            : coll.find(jsonToDBObject(matcher), jsonToDBObject(keys));
    if (skip != -1) {
        cursor.skip(skip);
    }
    if (limit != -1) {
        cursor.limit(limit);
    }
    if (sort != null) {
        cursor.sort(sortObjectToDBObject(sort));
    }
    sendBatch(message, cursor, batchSize);
}

From source file:org.wikidata.couchbase.MongoPersistHandler.java

License:Open Source License

@Override
public List<DBObject> load(int start, int limit) {
    DBCursor cursor = getCollection().find();
    cursor.skip(start);
    cursor.limit(limit);/*from   w ww  . j av  a  2s .  c o m*/
    List<DBObject> result = new LinkedList<DBObject>();
    try {
        while (cursor.hasNext()) {
            result.add(cursor.next());
        }
    } finally {
        cursor.close();
    }
    return result;
}