Example usage for com.mongodb.client.model CountOptions skip

List of usage examples for com.mongodb.client.model CountOptions skip

Introduction

In this page you can find the example usage for com.mongodb.client.model CountOptions skip.

Prototype

int skip

To view the source code for com.mongodb.client.model CountOptions skip.

Click Source Link

Usage

From source file:step.core.accessors.Collection.java

License:Open Source License

public CollectionFind<Document> find(Bson query, SearchOrder order, Integer skip, Integer limit) {
    //      StringBuilder query = new StringBuilder();
    //      List<Object> parameters = new ArrayList<>();
    //      if(queryFragments!=null&&queryFragments.size()>0) {
    //         query.append("{$and:[");
    //         Iterator<String> it = queryFragments.iterator();
    //         while(it.hasNext()) {
    //            String criterium = it.next();
    //            query.append("{"+criterium+"}");
    //            if(it.hasNext()) {
    //               query.append(",");
    //            }
    //         }//  ww  w .j a  va 2s. co m
    //         query.append("]}");
    //      }

    //      StringBuilder sort = new StringBuilder();
    //      sort.append("{").append(order.getAttributeName()).append(":")
    //         .append(Integer.toString(order.getOrder())).append("}");

    long count = collection.count();

    CountOptions option = new CountOptions();
    option.skip(0).limit(DEFAULT_LIMIT);
    long countResults = collection.count(query, option);

    FindIterable<Document> find = collection.find(query);
    if (order != null) {
        Document sortDoc = new Document(order.getAttributeName(), order.getOrder());
        find.sort(sortDoc);
    }
    if (skip != null) {
        find.skip(skip);
    }
    if (limit != null) {
        find.limit(limit);
    }
    return new CollectionFind<Document>(count, countResults, find.iterator());
}