List of usage examples for com.mongodb.client FindIterable maxTime
FindIterable<TResult> maxTime(long maxTime, TimeUnit timeUnit);
From source file:org.opencb.commons.datastore.mongodb.MongoDBNativeQuery.java
License:Apache License
public FindIterable<Document> find(Bson query, Bson projection, QueryOptions options) { if (projection == null) { projection = getProjection(projection, options); }// w ww.java 2 s .c o m FindIterable<Document> findIterable = dbCollection.find(query).projection(projection); int limit = (options != null) ? options.getInt(QueryOptions.LIMIT, 0) : 0; if (limit > 0) { findIterable.limit(limit); } int skip = (options != null) ? options.getInt(QueryOptions.SKIP, 0) : 0; if (skip > 0) { findIterable.skip(skip); } Object sortObject = (options != null) ? options.get(QueryOptions.SORT) : null; if (sortObject != null) { if (sortObject instanceof Bson) { findIterable.sort(((Bson) sortObject)); } else if (sortObject instanceof String) { String order = options.getString(QueryOptions.ORDER, "DESC"); if (order.equalsIgnoreCase(QueryOptions.ASCENDING) || order.equalsIgnoreCase("ASC") || order.equals("1")) { findIterable.sort(Sorts.ascending(((String) sortObject))); } else { findIterable.sort(Sorts.descending(((String) sortObject))); } } } if (options != null && options.containsKey(MongoDBCollection.BATCH_SIZE)) { findIterable.batchSize(options.getInt(MongoDBCollection.BATCH_SIZE, 20)); } if (options != null && options.containsKey(QueryOptions.TIMEOUT)) { findIterable.maxTime(options.getLong(QueryOptions.TIMEOUT), TimeUnit.MILLISECONDS); } return findIterable; }