Simple and easy to use Pagination with information like Total, Page, PerPage, Prev, Next and TotalPage.
$ go get -u -v github.com/roshanr83/mongo-go-pagination
or with dep
$ dep ensure -add github.com/roshanr83/mongo-go-pagination
filter := bson.M{}
var limit int64 = 10
var page int64 = 1
paging := PagingQuery{
collection: db.Collection(DatabaseCollectionName),
filter: filter,
limit: limit,
page: page,
sortField: "createdAt",
sortValue: -1,
}
paginatedData, err := paging.Find()
// paginated data is in paginatedData.Data
// pagination info can be accessed in paginatedData.Pagination
// if you want to marshal data to your defined struct
var lists []TodoTest
for _, raw := range paginatedData.Data {
var todo TodoTest
if err := bson.Unmarshal(raw, &todo); err == nil {
lists = append(lists, todo)
}
}
$ go test
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Copyright (c) 2020