/** * Select documents in collection and get a cursor to the selected documents. * * @param query the selection criteria using query operators. Omit the query parameter or pass an empty document to return all * documents in the collection. * @param projection specifies which fields MongoDB will return from the documents in the result set. * @param numToSkip number of documents to skip * @param batchSize see {@link DBCursor#batchSize(int)} for more information * @return A cursor to the documents that match the query criteria * @mongodb.driver.manual tutorial/query-documents/ Querying * @deprecated use {@link com.mongodb.DBCursor#skip(int)} and {@link com.mongodb.DBCursor#batchSize(int)} on the {@code DBCursor} * returned from {@link com.mongodb.DBCollection#find(DBObject, DBObject)} */ @Deprecated public DBCursor find(final DBObject query, final DBObject projection, final int numToSkip, final int batchSize) { return new DBCursor(this, query, projection, getReadPreference()).batchSize(batchSize).skip(numToSkip); }
protected <T extends Persisted> List<DBObject> query(Class<T> modelClass, DBObject query, DBObject sort, int limit, int offset) { return cursorToList( collection(modelClass) .find(query) .sort(sort) .limit(limit) .skip(offset) ); }
/** * Select documents in collection and get a cursor to the selected documents. * * @param query the selection criteria using query operators. Omit the query parameter or pass an empty document to return all * documents in the collection. * @param projection specifies which fields MongoDB will return from the documents in the result set. * @param numToSkip number of documents to skip * @param batchSize see {@link DBCursor#batchSize(int)} for more information * @param options query options to be used * @return A cursor to the documents that match the query criteria * @mongodb.driver.manual tutorial/query-documents/ Querying * @deprecated use {@link com.mongodb.DBCursor#skip(int)}, {@link com.mongodb.DBCursor#batchSize(int)} and {@link * com.mongodb.DBCursor#setOptions(int)} on the {@code DBCursor} returned from {@link com.mongodb.DBCollection#find(DBObject, * DBObject)} */ @Deprecated public DBCursor find(final DBObject query, final DBObject projection, final int numToSkip, final int batchSize, final int options) { return new DBCursor(this, query, projection, getReadPreference()).batchSize(batchSize).skip(numToSkip).setOptions(options); }
protected DBCursor createCursor(DBCollection collection, @Nullable Predicate where, Expression<?> projection, QueryModifiers modifiers, List<OrderSpecifier<?>> orderBy) { DBCursor cursor = collection.find(createQuery(where), createProjection(projection)); Integer limit = modifiers.getLimitAsInteger(); Integer offset = modifiers.getOffsetAsInteger(); if (limit != null) { cursor.limit(limit); } if (offset != null) { cursor.skip(offset); } if (orderBy.size() > 0) { cursor.sort(serializer.toSort(orderBy)); } if (readPreference != null) { cursor.setReadPreference(readPreference); } return cursor; }
c.skip(firstResult).limit(maxResult); while (c.hasNext())
/** * Discards a given number of elements at the beginning of the cursor. * * @param n the number of elements to skip * @return a cursor pointing to the new first element of the results * @throws RuntimeException if the cursor has started to be iterated through */ public DBCursor<T> skip(int n) { cursor.skip(n); return this; }
c = c.skip(q.getStartIndex());
: dbCollection.find(mongoQuery, keys).limit(maxResult).skip(firstResult);
/** * Find all document, and return one page * @param pageNum * @param pageSize * @return */ public List<T> findAll(int pageNum, int pageSize){ DBCursor cursor = getCollection().find(new BasicDBObject(), keys).skip((pageNum-1)*pageSize).limit(pageSize); return MapperUtil.toList(clazz, cursor); }
@Override @SuppressWarnings("unchecked") public <T> PaginatedResult<T> readPartial(Query<T> query, long offset, int limit) { List<T> list = new ArrayList<T>(); DBCursor cursor = find(query).skip((int) offset).limit(limit); for (DBObject item : cursor) { list.add((T) loadObject(item.toMap())); } return new PaginatedResult<T>(offset, limit, cursor.count(), list); }
@Override public List<DatabaseDocument<MongoType>> getDocuments( DatabaseQuery<MongoType> dbq, int limit, int skip) { DBCursor cursor = documents.find(((MongoQuery)dbq).toDBObject()).skip(skip).limit(limit); List<DatabaseDocument<MongoType>> list = new ArrayList<DatabaseDocument<MongoType>>(); while(cursor.hasNext()) { cursor.next(); list.add((MongoDocument)cursor.curr()); } return list; }
/** * @param coll * @param object * @return */ @Override public DBCollection apply(DBCollection coll, DBObject object) { List<DBObject> objects = coll.find().skip(((Number) object.get(getKeyword())).intValue()).toArray(); return dropAndInsert(coll, objects); }
/** * Find all document, and return one page * @param orderBy * @param pageNum * @param pageSize * @return */ public List<T> findAll(String orderBy, int pageNum, int pageSize){ DBObject dbo = SortUtil.getSort(orderBy); DBCursor cursor = getCollection().find(new BasicDBObject(), keys).sort(dbo).skip((pageNum-1)*pageSize).limit(pageSize); return MapperUtil.toList(clazz, cursor); }
protected <T extends Persisted> List<DBObject> query(Class<T> modelClass, DBObject query, DBObject sort, int limit, int offset) { return cursorToList( collection(modelClass) .find(query) .sort(sort) .limit(limit) .skip(offset) ); }
public List<GridFSDBFile> find(DBObject query, String orderBy, int pageNum, int pageSize){ DBObject sort = SortUtil.getSort(orderBy); DBCursor cursor = files.find(query).sort(sort).skip((pageNum-1)*pageSize).limit(pageSize); return toFileList(cursor); }
@Override public Collection<Resource> members(RequestContext ctx) throws Exception { LinkedList<Resource> members = new LinkedList<>(); // if children requested query children info DBCollection col = getUserspace().getFilesCollection(); DBCursor result = col.find().skip(ctx.pagination().offset()).limit(ctx.pagination().limit()); while (result.hasNext()) { DBObject child = result.next(); members.add(wrapDBObject(path(), new GridFSDBObject(child))); } return members; }
@Override public Page<Record> fetchRecords(StoreQuery query) { DBObject mongoQuery = convert(query); final BasicDBObject projection = query.isMetadataOnly() ? new BasicDBObject(BatchConstants.metadataKey, 1) : null; DBCursor cursor = accessor.getCollection().find(mongoQuery, projection); cursor.sort(createOrderBy(query)); cursor = cursor.skip(query.getPageSize() * query.getPageNo()); cursor = cursor.limit(query.getPageSize()); return convert(cursor, query); }
@Override public List<UserData> getUsersInDomain(String domain, int startIndex, int count) { DBObject queryObj = BasicDBObjectBuilder.start() .add(FIELD_DOMAIN, domain) .add(FIELD_CREATION_STATE, DataCreationState.Created.toString()) .get(); DBCursor cursor = collection.find(queryObj).skip(startIndex).limit(count); return fromDBCursor(cursor); }
@Override public List<UserData> getUsersByCreationState(DataCreationState creationState, int startIndex, int count) { DBObject queryObj = BasicDBObjectBuilder.start() .add(FIELD_CREATION_STATE, creationState.toString()) .get(); DBObject sortObj = BasicDBObjectBuilder.start() .add(FIELD_RANDOMIZER, 1) .get(); DBCursor cursor = collection.find(queryObj).sort(sortObj).skip(startIndex).limit(count); return fromDBCursor(cursor); }