Package org.graylog2.database.pagination
Interface MongoPaginationHelper<T extends MongoEntity>
- Type Parameters:
T- Type of documents in the underlying MongoDB collection.
- All Known Implementing Classes:
DefaultMongoPaginationHelper
public interface MongoPaginationHelper<T extends MongoEntity>
A utility class that provides paged access to a MongoDB collection.
Implementing classes should be immutable so that instances can be re-used.
-
Method Summary
Modifier and TypeMethodDescriptioncollation(com.mongodb.client.model.Collation collation) Sets a collation to be used in the find operation.filter(org.bson.conversions.Bson filter) Sets the query filter to apply to the query.grandTotalFilter(org.bson.conversions.Bson grandTotalFilter) Sets a filter to be applied to the query to count the grand total of documents in the collection.includeGrandTotal(boolean includeGrandTotal) Specifies whether to include a grand total number of all documents in the collection.page(int pageNumber) Perform the MongoDB request and return the specified page.Perform the MongoDB request but apply the given predicate to each document in the list of results and only keep documents matching the predicate.perPage(int perPage) Sets the page size.projection(org.bson.conversions.Bson projection) Sets the projection BSON to apply to the query.sort(org.bson.conversions.Bson sort) Sets the sort criteria to apply to the query.
-
Method Details
-
filter
Sets the query filter to apply to the query.- Parameters:
filter- the filter, which may be null.- Returns:
- A new pagination helper with the setting applied
-
sort
Sets the sort criteria to apply to the query.- Parameters:
sort- the sort criteria, which may be null.- Returns:
- A new pagination helper with the setting applied
-
projection
Sets the projection BSON to apply to the query. It will limit the number of fields retrieved from MongoDB for each document. Keep in mind that you can only exclude fields that are optional in related MongoEntity and you are responsible for ensuring that excluded fields are not needed in your use case.- Parameters:
projection- the projection BSON, which may be null.- Returns:
- A new pagination helper with the setting applied
-
perPage
Sets the page size.- Parameters:
perPage- the number of documents to put on one page- Returns:
- A new pagination helper with the setting applied
-
includeGrandTotal
Specifies whether to include a grand total number of all documents in the collection. No filters, except, if set, thegrandTotalFilter(Bson)will be applied to the count query.- Parameters:
includeGrandTotal- true if a grand total should be included. Otherwise, by default, no grand total will be included.- Returns:
- A new pagination helper with the setting applied
-
grandTotalFilter
Sets a filter to be applied to the query to count the grand total of documents in the collection.- Parameters:
grandTotalFilter- the filter, which may be null- Returns:
- A new pagination helper with the setting applied
-
collation
Sets a collation to be used in the find operation.- Parameters:
collation- The collation to set. If null, uses the default server collation- Returns:
- A new pagination helper with the setting applied
-
page
Perform the MongoDB request and return the specified page.- Parameters:
pageNumber- The number of the page to be returned.- Returns:
- a paginated list of documents
-
page
Perform the MongoDB request but apply the given predicate to each document in the list of results and only keep documents matching the predicate.This is a potentially expensive operation because the selector can only be applied after the documents have been fetched from MongoDB and this might result in a full collection scan. Use with care!
- Parameters:
pageNumber- The number of the page to be returned.selector- predicate to filter documents after fetching them from MongoDB.- Returns:
- a paginated list of documents
-