Documentation ¶
Overview ¶
Package mongocursorpagination eases the computation of pagination information of a find mongo query by augmenting the base query with cursor information and returning a cursor.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
type Cursor struct { // The URL safe previous page cursor to pass in a Find call to get the previous page. // This is set to the empty string if there is no previous page. Previous string // The URL safe next page cursor to pass in a Find call to get the next page. // This is set to the empty string if there is no next page. Next string // true if there is a previous page, false otherwise HasPrevious bool // true if there is a next page, false otherwise HasNext bool // Total count of documents matching filter - only computed if CountTotal is True Count int }
Cursor holds the pagination data about the find mongo query that was performed.
func Find ¶
func Find(p FindParams, results interface{}) (Cursor, error)
Find executes a find mongo query by using the provided FindParams, fills the passed in result slice pointer and returns a Cursor.
type CursorError ¶
type CursorError struct {
// contains filtered or unexported fields
}
func (*CursorError) Error ¶
func (e *CursorError) Error() string
type FindParams ¶
type FindParams struct { // The mongo database to use DB MgoDb // The name of the mongo collection to query CollectionName string // The find query to augment with pagination Query bson.M // The number of results to fetch, should be > 0 Limit int // true, if the results should be sort ascending, false otherwise SortAscending bool // The name of the mongo collection field being paginated and sorted on. This field must: // 1. Be orderable. We must sort by this value. If duplicate values for paginatedField field // exist, the results will be secondarily ordered by the _id // 2. Be indexed. For large collections, this should be indexed for query performance // 3. Be immutable. If the value changes between paged queries, it could appear twice // 4. Match the bson field name the result struct. e.g.: // // PaginatedField would be "name" when paginating employees by name // // type Employee struct { // ID bson.ObjectId `bson:"_id"` // Name string `bson:"name"` // } // PaginatedField string // The collation to use for the sort ordering. // See https://docs.mongodb.com/manual/reference/collation-locales-defaults/#supported-languages-and-locales // This is ignored if PaginatedField is empty Collation *mgo.Collation // The value to start querying the page Next string // The value to start querying previous page Previous string // Whether or not to include total count of documents matching filter in the cursor // Specifying true makes an additionnal query CountTotal bool }
FindParams holds the parameters to be used in a paginated find mongo query that will return a Cursor.
type MgoDb ¶
type MgoDb interface {
C(string) *mgo.Collection
}
Click to show internal directories.
Click to hide internal directories.