@Override public GridFSFindIterable skip(final int skip) { underlying.skip(skip); return this; }
@Signature public WrapMongoIterable skip(int n) { if (getWrappedObject() instanceof FindIterable) { return new WrapMongoIterable(this.__env__, ((FindIterable) getWrappedObject()).skip(n)); } else { return this; } }
@SuppressWarnings("resource") @Override public List<T> call() throws Exception { @Nullable Bson query = criteria != null ? convertToBson(criteria) : null; FindIterable<T> cursor = collection().find(query); if (!exclusion.isNil()) { cursor.projection(convertToBson(exclusion)); } if (!ordering.isNil()) { cursor.sort(convertToBson(ordering)); } cursor.skip(skip); if (limit != 0) { cursor.limit(limit); if (limit <= LARGE_BATCH_SIZE) { // if limit specified and is smaller than reasonable large batch size // then we force batch size to be the same as limit, // but negative, this force cursor to close right after result is sent cursor.batchSize(-limit); } } // close properly try (MongoCursor<T> iterator = cursor.iterator()) { return ImmutableList.copyOf(iterator); } } });
cursorToUse = cursorToUse.skip((int) query.getSkip());
@Override public Stream<Map<String, Object>> all(Map<String, Object> query, Long skip, Long limit) { FindIterable<Document> documents = query == null ? collection.find() : collection.find(new Document(query)); if (skip != 0) documents = documents.skip(skip.intValue()); if (limit != 0) documents = documents.limit(limit.intValue()); return asStream(documents); }
@Override public Stream<Map<String, Object>> find(Map<String, Object> query, Map<String, Object> project, Map<String, Object> sort, Long skip, Long limit) { FindIterable<Document> documents = query == null ? collection.find() : collection.find(new Document(query)); if (project != null) documents = documents.projection(new Document(project)); if (sort != null) documents = documents.sort(new Document(sort)); if (skip != 0) documents = documents.skip(skip.intValue()); if (limit != 0) documents = documents.limit(limit.intValue()); return asStream(documents); }
@Override public GridFSFindIterable skip(final int skip) { underlying.skip(skip); return this; }
@Override public GridFSFindIterable skip(final int skip) { underlying.skip(skip); return this; }
@Override public FindOperationConfigurator skip(int skip) { iterable.skip(skip); return this; }
cursorToUse = cursorToUse.skip((int) query.getSkip());
private FindIterable<Document> applyQueryParams(FindIterable<Document> findIterable, Optional<QueryParams> queryParams) { if (queryParams.isPresent()) { QueryParams params = queryParams.get(); findIterable = findIterable .limit(params.limit()) .skip(params.skip()); } return findIterable; }
private FindIterable<Document> applyQueryParams(FindIterable<Document> findIterable, Optional<QueryParams> queryParams) { if (queryParams.isPresent()) { QueryParams params = queryParams.get(); findIterable = findIterable .limit(params.limit()) .skip(params.skip()); } return findIterable; }
private FindIterable<Document> getFindIterable(int skip, int limit) { return collection() .find() .skip(skip) .limit(limit); }
public List<V> findAll(int skip, int limit) { return collection() .find() .skip(skip) .limit(limit) .map(this::decode) .into(new ArrayList<>()); }
private FindIterable<Document> find(int page){ final FindIterable<Document> documents = oplog .find(query) .sort(new Document("$natural", 1)) .skip(page * batchSize) .limit(batchSize) .projection(Projections.include("ts", "op", "ns", "o")) .cursorType(CursorType.TailableAwait); return documents; }
public List<JSONObject> find(String collectionName, Bson query, Bson sort, Bson projection, int limit, int skip, final String join) { final List<JSONObject> list = new ArrayList<JSONObject>(); Block<Document> block = new Block<Document>() { public void apply(Document document) { document = iding(document); document = jointing(document, join); list.add(toJSON(document)); } }; getCollection(collectionName).find(query).projection(projection).sort(sort).limit(limit).skip(skip).forEach(block); return list; }
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; } return false; }
@Test public void testFindWithSkipLimitInReverseOrder() { collection.insertOne(json("_id: 1")); collection.insertOne(json("_id: 2")); collection.insertOne(json("_id: 3")); collection.insertOne(json("_id: 4")); assertThat(toArray(collection.find().sort(json("_id: -1")).limit(2).skip(2))) .containsExactly(json("_id: 2"), json("_id: 1")); }
@Test public void testFindWithSkipLimit() { collection.insertOne(json("_id: 1")); collection.insertOne(json("_id: 2")); collection.insertOne(json("_id: 3")); collection.insertOne(json("_id: 4")); assertThat(toArray(collection.find().sort(json("_id: 1")).limit(2).skip(2))) .containsExactly(json("_id: 3"), json("_id: 4")); }
@Test public void testFindWithSkipLimitAfterDelete() { collection.insertOne(json("_id: 1")); collection.insertOne(json("_id: 2")); collection.insertOne(json("_id: 3")); collection.insertOne(json("_id: 4")); collection.insertOne(json("_id: 5")); collection.deleteOne(json("_id: 1")); collection.deleteOne(json("_id: 3")); assertThat(toArray(collection.find().sort(json("_id: 1")).limit(2).skip(2))) .containsExactly(json("_id: 5")); }