Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@mother/mongoose-cursor-pagination
Advanced tools
Easy-to-use, scalable, cursor pagination plugin for mongoose
This small plugin makes it easy to use cursor-based pagination in your app, without changing the way you use queries in mongoose.
npm install @mother/mongoose-cursor-pagination --save
Node.js 10.x or higher is required.
In your schema:
import mongoose from 'mongoose'
import paginationPlugin from '@mother/mongoose-cursor-pagination'
const CommentSchema = new mongoose.Schema({
date: { type: Date },
body: { type: String },
author: {
firstName: { type: String },
lastName: { type: String }
}
})
CommentSchema.plugin(paginationPlugin)
In your application code:
const { results, pageInfo } = await Comment
.find({}) // Whatever filter you want
.limit(30) // Use limit and other Query options as you normally would
.sort('author.lastName') // Use sort as you would normally do
.paginate(startCursor) // startCursor optional
.exec() // Required
results
will be the results that you would expect from a normal mongoose find
query
pageInfo
will have two properties: hasNext
and nextCursor
Be sure to index correctly. Note that this plugin always add _id
to the sort key to ensure cursors are unique, so include that in your index as well. For example, say you are using the date
field for pagination, then you would want to setup the index:
commentSchema.index({ date: -1, _id: -1 })
You can optionally pass an options object to this plugin:
CommentSchema.plugin(paginationPlugin, {
// If no limit is specified, and paginate() is being used,
// what should the default limit be.
defaultLimit: 100
})
Numerous tests are included in the tests
directory, and can be run using the command npm test
.
hasPrev
and prevCursor
exec
calls that use callbacks instead of promisesMIT
FAQs
Easy-to-use, scalable, cursor pagination plugin for mongoose
The npm package @mother/mongoose-cursor-pagination receives a total of 24 weekly downloads. As such, @mother/mongoose-cursor-pagination popularity was classified as not popular.
We found that @mother/mongoose-cursor-pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.