
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@enkidevs/mongoose-cursor-pagination
Advanced tools
Mongoose cursor-based pagination
npm install mongoose-cursor-pagination --save
The plugin utilises cursor-based pagination via the startingAfter
and endingBefore
parameters.
Both take an existing value (see below) and return objects in reverse chronological order.
The endingBefore
parameter returns objects listed before the named object.
The startingAfter
parameter returns objects listed after the named object.
If both parameters are provided, only endingBefore
is used.
Moreover, an optional limit
parameter can be passed to limit the amount of objects returned.
Add the plugin to a schema:
import mongoose from 'mongoose'
import paginationPlugin from 'mongoose-cursor-pagination'
const AccountSchema = new mongoose.Schema({
username: { type: Number, unique: true, index: true }
})
AccountSchema.plugin(paginationPlugin)
mongoose.model('Account', AccountSchema)
and then use the model paginate method using a promise:
mongoose.model('Account').paginate({}, {
sort: { '_id': 1 },
startingAfter: '59b1f7fd41cfc303859ea1c9',
limit: 20
})
.then(results => { /* ... */ })
.catch(error => { /* ... */ })
or using a callback:
mongoose.model('Account').paginate({}, {
sort: { '_id': 1 }
}, (error, results) => {
/* ... */
})
A possible value for results
is:
{
items: [ /* ... */ ],
hasMore: true
}
where items
is an array containing the elements, and hasMore
is true
if there are more elements available after this set. Or false
otherwise.
The default plugin values can be overwritten, here we show the default values:
AccountSchema.plugin(paginationPlugin, {
key: '_id',
limit: 20,
maxLimit: 100,
minLimit: 1
})
The key
specified is assumed to be unique and should have an index associated.
Moreover, when paginating the key
should be sorted ascending order and the values of startingAfter
and endingBefore
should contained values for that key
.
npm install
npm test
FAQs
Mongoose cursor-based pagination.
We found that @enkidevs/mongoose-cursor-pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.