Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
mongoose-simple-pagination
Advanced tools
Readme
Mongoose simple pagination plugin written specially for typescript and async purposes.
I created this package because I met typing problems in alternative libraries such as mongoose-paginate-v2. This package is for people who looking for typescript solution with typings.
npm i mongoose-simple-pagination
Add plugin to a schema and then use model paginate
method:
import { Document, model, Schema } from 'mongoose';
import { mongooseSimplePagination, PaginationModel } from 'mongoose-simple-pagination';
interface Product extends Document {
// ...
}
const productSchema = new Schema<Product>(
{
// ...
}
);
productSchema.plugin(mongoosePaginate);
export const ProductModel = model<Product, PaginationModel<Product>>(
'Product',
productSchema,
'products'
);
(async () => {
const pagination = await ProductModel.paginate();
const products = pagination.documents; // Our products array.
const hasNextPage = pagination.hasNextPage; // true.
})();
Returns promise
Parameters
[filter]
{FilterQuery} - Filter query criteria. Documentation[options]
{Options}
[collation]
{CollationDocument} - Specify the collation. Documentation[lean=false]
{boolean | any} - Should return plain javascript objects instead of Mongoose document object.[page=1]
{number}[perPage=20]
{number}[populate]
{string | PopulateOptions | PopulateOptions[]} - Paths which should be populated with other
documents. Documentation[projection=null]
{any | null} - Get/set the query
projection. Documentation[queryOptions={}]
{QueryOptions | null} - Query options passed to Mongoose's find()
function. Documentation[select='']
{string | any} - Fields to return (by default returns all fields)
. Documentation[sort='']
{string | any} - Sort order. DocumentationReturn value
Promise fulfilled with Pagination object having properties:
documents
{T[]} - Array of documents.hasNextPage
{bool} - Availability of next page.hasPreviousPage
{bool} - Availability of previous page.nextPage
{number} - Next page number if available or NULL.page
{number} - Current page number.perPage
{number} - Number of documents per page.previousPage
{number} - Previous page number if available or NULL.totalDocuments
{number} - Total number of documents in collection that match a query.totalPages
{number} - Total number of pages.FAQs
Mongoose simple pagination plugin written specially for typescript and async purposes
The npm package mongoose-simple-pagination receives a total of 0 weekly downloads. As such, mongoose-simple-pagination popularity was classified as not popular.
We found that mongoose-simple-pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.