List of usage examples for com.mongodb.client FindIterable skip
FindIterable<TResult> skip(int skip);
From source file:com.bluedragon.mongo.MongoCollectionFind.java
License:Open Source License
public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException { MongoDatabase db = getMongoDatabase(_session, argStruct); String collection = getNamedStringParam(argStruct, "collection", null); if (collection == null) throwException(_session, "please specify a collection"); cfData query = getNamedParam(argStruct, "query", null); if (query == null) throwException(_session, "please specify query"); int size = getNamedIntParam(argStruct, "size", -1); int skip = getNamedIntParam(argStruct, "skip", -1); cfData sort = getNamedParam(argStruct, "sort", null); cfData fields = getNamedParam(argStruct, "fields", null); try {/* w ww. ja v a2 s .co m*/ MongoCollection<Document> col = db.getCollection(collection); // Get the initial cursor FindIterable<Document> cursor; long start = System.currentTimeMillis(); Document qry = getDocument(query); cursor = col.find(qry); if (fields != null) cursor = cursor.projection(getDocument(fields)); // Are we sorting? if (sort != null) cursor = cursor.sort(getDocument(sort)); // Are we limiting if (skip != -1) cursor = cursor.skip(skip); // How many we bringing back if (size != -1) cursor = cursor.limit(size); // Now we can run the query cfArrayData results = cfArrayData.createArray(1); cursor.forEach(new Block<Document>() { @SuppressWarnings("rawtypes") @Override public void apply(final Document st) { try { results.addElement(tagUtils.convertToCfData((Map) st)); } catch (cfmRunTimeException e) { } } }); _session.getDebugRecorder().execMongo(col, "find", qry, System.currentTimeMillis() - start); return results; } catch (MongoException me) { throwException(_session, me.getMessage()); return null; } }
From source file:com.eclipsesource.connect.persistence.MongoStorage.java
License:Open Source License
private FindIterable<Document> prepareIterable(Query<?> query, FindIterable<Document> iterable) { if (query.getLimit() != -1) { iterable.limit(query.getLimit()); }/* w ww .j a va 2 s.c o m*/ if (query.getSortField() != null) { iterable.sort( new Document(query.getSortField(), query.getSortDirection() == SortDirection.ASC ? 1 : -1)); } if (query.getSkip() != Query.UNDEFINED) { iterable.skip(query.getSkip()); } return iterable; }
From source file:com.github.cherimojava.data.mongo.query.QueryInvocationHandler.java
License:Apache License
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); switch (methodName) { case "e": // this is just a handout for the entity to get knowledge of what to check return this.entityProxy.get(); case "where":/* fallthrough */ case "and": return this.specifier.get(); case "iterator": FindIterable it = coll.find(Filters.and(filters.toArray(new Bson[] {}))); if (limit != null) { it.limit(limit);// w w w. j a v a 2s. co m } if (skip != null) { it.skip(skip); } if (sorts.size() > 0) { it.sort(Sorts.orderBy(sorts)); } return it.iterator(); case "count": return coll.count(Filters.and(filters.toArray(new Bson[] {}))); case "limit": limit = (Integer) args[0]; return queryEnd.get(); case "skip": skip = (Integer) args[0]; return queryEnd.get(); case "sort": checkState(!sortSet, "Sorting can be specified only once"); sortSet = true; return querySort.get(); case "desc":/* fallthrough */ case "asc": return addSortInformation("asc".equals(methodName)); case "by": return addSortInformation(args[0] == QuerySort.Sort.ASC); } throw new IllegalStateException("Unknown method found: " + methodName); }
From source file:com.github.cherimojava.orchidae.controller.PictureController.java
License:Apache License
/** * Returns a list (json) with the {number} most recent photos of the given {user}. * * @param user/*from www. j a v a2s.c om*/ * to retrieve pictures from * @param number * (optional) number of pictures to ask for. Number is constrained by {@link #latestPictureLimit} * @param skip * number of pictures to skip. Must be non negativ * @return picture json list with the latest pictures * @since 1.0.0 */ @RequestMapping(value = "/{user}/latest", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @PostFilter("@paa.hasAccess(filterObject.id)") public List<Picture> latestPicturesMetaByUserLimit(@PathVariable("user") String user, @RequestParam(value = "n", required = false) Integer number, @RequestParam(value = "s", required = false) Integer skip) { if (number == null || number > latestPictureLimit) { LOG.info("latest picture request was ({}) greater than max allowed {}. Only returning max", number, latestPictureLimit); number = latestPictureLimit; } FindIterable<Picture> it = factory.getCollection(Picture.class) .find(new BsonDocument("user", new BsonString(user)), Picture.class).limit(number) .sort(new Document("order", -1)); if (skip != null && skip > 0) { it.skip(skip); } return Lists.newArrayList(it); }
From source file:io.lumeer.storage.mongodb.dao.MongoDao.java
License:Open Source License
public <T> void addPaginationToSuggestionQuery(FindIterable<T> findIterable, DatabaseQuery query) { Integer page = query.getPage(); Integer pageSize = query.getPageSize(); if (page != null && pageSize != null) { findIterable.skip(page * pageSize).limit(pageSize); }//from w w w. j a v a2 s. com }
From source file:io.lumeer.storage.mongodb.dao.project.MongoViewDao.java
License:Open Source License
@Override public List<View> getViews(SearchQuery query) { FindIterable<JsonView> findIterable = databaseCollection().find(MongoViewDao.viewSearchFilter(query)); if (query.hasPagination()) { findIterable.skip(query.getPage() * query.getPageSize()).limit(query.getPageSize()); }//from ww w . j av a 2 s . c om return findIterable.into(new ArrayList<>()); }
From source file:io.lumeer.storage.mongodb.MongoDbStorage.java
License:Open Source License
@Override public List<DataDocument> search(String collectionName, DataFilter filter, final DataSort sort, List<String> attributes, final int skip, int limit) { MongoCollection<Document> collection = database.getCollection(collectionName); FindIterable<Document> documents = filter != null ? collection.find(filter.<Bson>get()) : collection.find(); if (sort != null) { documents = documents.sort(sort.<Bson>get()); }//from w w w .j av a2 s. com if (attributes != null && !attributes.isEmpty()) { documents.projection(Projections.fields(Projections.include(attributes))); } if (skip > 0) { documents = documents.skip(skip); } if (limit > 0) { documents = documents.limit(limit); } return MongoUtils.convertIterableToList(documents); }
From source file:net.springfieldusa.storage.mongodb.comp.MongoStorageComponent.java
License:Open Source License
private <T extends EntityObject> Collection<T> find(String collection, Document query, int skip, int limit, Supplier<T> factory) { FindIterable<Document> cursor = getCollection(collection).find(query); if (skip > 0) cursor.skip(skip); if (limit > 0) cursor.limit(limit);//ww w . j a v a 2s . co m Collection<T> items = new ArrayList<>(); for (Document value : cursor) items.add(createObject(factory, value)); return items; }
From source file:net.ymate.platform.persistence.mongodb.impl.MongoSession.java
License:Apache License
protected boolean __doPageInit(FindIterable<Document> findIterable, Page page) { if (page != null && page.page() > 0 && page.pageSize() > 0) { findIterable.skip((page.page() - 1) * page.pageSize()).limit(page.pageSize()); return true; }//from ww w . j a v a2 s . c o m return false; }
From source file:org.apache.metamodel.mongodb.mongo3.MongoDbDataContext.java
License:Apache License
private MongoCursor<Document> getDocumentMongoCursor(Table table, List<FilterItem> whereItems, int firstRow, int maxRows) { final MongoCollection<Document> collection = _mongoDb.getCollection(table.getName()); final Document query = createMongoDbQuery(table, whereItems); logger.info("Executing MongoDB 'find' query: {}", query); FindIterable<Document> iterable = collection.find(query); if (maxRows > 0) { iterable = iterable.limit(maxRows); }/*from w w w. jav a 2s . c om*/ if (firstRow > 1) { final int skip = firstRow - 1; iterable = iterable.skip(skip); } return iterable.iterator(); }