npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@omegion1npm/ipsam-ullam-rem

v1.0.0

Published

[![npm version](https://img.shields.io/npm/v/@omegion1npm/ipsam-ullam-rem.svg)](https://www.npmjs.com/package/@omegion1npm/ipsam-ullam-rem) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://g

Downloads

4

Maintainers

ptkhanh1994ptkhanh1994

Keywords

css nestinggradients csscensortestxssRegExp.prototype.flagsredux-toolkitonceArrayBuffer#slicewaapicommandertextconcurrencyMicrosofttranspilertypesafeeslintconfiginterruptsprocessconfigjson-schema-validationvalidationObject.entrieswatchingopenl10ngetPrototypeOfAsyncIteratorthreemimetypesformattinglinuxfunctionalgroupBycompile lesssuperstruct.envTypedArraycopyUnderscorerm -froptimizertranspileSymbolcssdatastructureprivate dataArraycolorsemitsymbolswatchkeysapolloless compilerlimitES7ttyprotowordwrapinspectArray.prototype.containsconcatMapbundlingES3eslint-pluginfull-widthloading0pruneBigUint64ArraytypeObjectlistenersshimzeroperformantassignspeedTypeScriptdebuggerrequestes2017exewriteObservablesqueueMicrotaskECMAScript 2020String.prototype.trimURLSearchParamslesstc39ECMAScript 2022cmddescriptorscomparekoreancryptstreams2japaneseassertioncoerciblecompilernativesanitizationstreamdayjsjsonschemaObject.istraversehookformiteratetoolkitvarglob__proto__mapgetwalkinges-shimsajaxnameexpressionECMAScript 2018flatzodfast-deep-copyReactiveExtensionsenvironmentiteratordependency managervisualcurriedvalidatorjavascriptTypeBoxsetPrototypeOfdotenvequalxdg-openobjes-abstractWebSocketYAMLwaitES2019Array.prototype.findLasttslibpushReflect.getPrototypeOfxtermCSSStyleDeclarationtrimLeftlibphonenumbererror-handlingFloat64Arrayconstpromisesanimationcall-bindflatMaplazylimitedUint16Arrayartdescriptorclishamreact-hooksUint8ClampedArrayreducerjson-schemapolyfillwarningcore-jsnodehasOwnschemaconsumeES2016fast-clone256@@toStringTagsuperagentmruprogresscode pointsformstructuredClonediffpromisedependenciesUint8Arraydeep-copychromecss lessdeepcopyrateenderboundfastclonermsafeES2022signalsES5colourthrottlestableweakmaptelephonewebeverymixinsserializationqssearchfullwidthcharacteropensECMAScript 2021colordragstartharmonywhichmatchphonebusyerrorstylesymbolfantasy-landautoprefixerjsontyped arraydirectoryefficienttddpositivejsonpathregexfastInt8ArraywindowstoobjectwatchFilewalkWeakSetflagposebabeldom-testing-librarysorttrimpreprocessorhookspackage managerargumentformatextensionprotobuf[[Prototype]]datayupdeep-clonecallbackkeytapmomentgraphqla11yterminal_.extendbundleropenerrm -rfchanneltrimEndwrapMapIteratorgetOwnPropertyDescriptorES2023pnpm9persistentmkdirpES2018trimStartutilitiesfastifyWebSocketsletclassespicomatchloggercallRxsanitizeparentslinkeventDispatcherinternal slotyamlvariablesstringmatchAllsameValueZerolesscssrecursivepropertybindimmerdropmiddlewareesratelimitpackagesECMAScript 3throatuser-streamsgetterstringifiercorenamesshellfindLastmacoses8ECMAScript 2016fpparentArray.prototype.flatMapsymlinkshashwordbreakmatchesfigletInt16Arrayflattencachefilees2016upapiless cssStyleSheetsettingspoint-freelookutiltypanionwatcherlengthdataViewstylesheettsfile systeminferencejestperformancecreateregular expressionspostcss-pluginUint32ArrayhardlinksECMAScript 7WeakMappureworkertypesclientreduxSetfolderquotetypedreadconnectjsxprototypereducedataviewfsJSONmake dirmergebrowserlogginges-shim APIcallbindeventEmittertapekarmabytechildremoveeast-asian-widthObject.valuescryptostylingjwtarrayavaObject.definePropertyes5exit-codeemojifindLastIndexbootstrap lessmodulejsdombreakcircularoffsetlaunchpreserve-symlinksbrowserlistrandomprefixtoolsescapereact animationcurlReactiveXomitoptimistbufferprettyObject.keyses2018symlinkES2015ecmascriptlanguagesignaldefinemkdirrobustlruform-validationworkspace:*widthmimebrowserslistparserBigInt64Arrayfixed-widthnumbertypedarrayfastcopyhelpersnested cssexpressnegativeawesomesaucequerystringeslintpluginextendstringifyprotocol-bufferssigintexecutablecolumnscall-boundrangeerrorarktypeasyncauthenticationES2021descriptionutilityRegExp#flagsCSSslotnodejsviewimmutableclassnamesserializeidlegesturesoperating-systempackage.jsongetoptsettacitinputintrinsicmonorepoformspyyamlES6urlArray.prototype.filtercjktoArrayenumerablecontainsECMAScript 2023slicenpmestreefindreactelectronauthconfigurablestylesdefinePropertytypeofvalidlinthttpinvariantpathsequenceforEachbuffersqueryclassnamearraybufferStreamsvalueslogjQueryreact-hook-formSymbol.toStringTagcommand-linesortedArray.prototype.flatchaiduplexes2015jasminexdgindicatorcharactersruntimeimportprivatepasswordcodescss-in-jssettertaskgradients css3concatmakeHyBieslintframeworkrfc4122uuidsharedisnopestatelessweaksetjoitoStringTagargvtypedarraystostringtagpropertiesarraysstarterECMAScript 2017fast-deep-clonefunctionlastfunctionswhatwgFunction.prototype.namedirpropschemeequalityESES2017sideinstallregexptakeflagsInt32Arraywritableregular expressionexecmochaspinnerassertdeepclonecheckvariables in csstrimRightmovevaluecollection.es6assertsArray.prototype.includespopmotionrmdirreadablestreamiterationpackagejscomputed-typespatchaccessibilityspringless mixinscss variableES8toSortededitorbatchdateURLbddurlsspectimeECMAScript 2015exitrgbRxJSrequiresyntaxerrorairbnbclass-validatorObject.getPrototypeOfserializerhigher-ordertestingmime-dbparsebannerawaitObservablecloneio-tshasECMAScript 20196to5rapidredactfindupisConcatSpreadablesigtermsharedarraybufferPushes7xhrdefaultmetadatapostcssargumentsfast-copyshrinkwrapmobile-0look-upArray.prototype.flattenfromstyleguideoptionextraArray.prototype.findLastIndexwebsiteObject.assignESnextlockfileutilsPromiseencryptioncorsStreamreadablefetchinternalFloat32Arraygdproutputscheme-validationECMAScript 6handlersreuseshebangregularidreal-timeponyfillresolvespawntypeerrorenvdeterministicgetintrinsicplugindeletechromiumutil.inspectArrayBuffer.prototype.sliceES2020String.prototype.matchAllfullbyteOffsetjsdiffECMAScript 5accessorsetImmediateobjectwgetastsyntaxchinesestreamstermhttpsfind-upjson-schema-validatorvalidategenericsqueuecallboundRFC-6455vestbluebirdfilterramdaappargparsebabel-corecommandframerasciigroupentriesdeep

Readme

@omegion1npm/ipsam-ullam-rem

npm version contributions welcome Downloads

A cursor based custom aggregate pagination library for Mongoose with customizable labels.

If you are looking for basic query pagination library without aggregate, use this one mongoose-paginate-v2

Installation

npm install @omegion1npm/ipsam-ullam-rem

Usage

Adding the plugin to a schema,

var mongoose = require("mongoose");
var aggregatePaginate = require("@omegion1npm/ipsam-ullam-rem");

var mySchema = new mongoose.Schema({
  /* your schema definition */
});

mySchema.plugin(aggregatePaginate);

var myModel = mongoose.model("SampleModel", mySchema);

and then use model aggregatePaginate method,

// as Promise

var myModel = require("/models/samplemodel");

const options = {
  page: 1,
  limit: 10,
};

var myAggregate = myModel.aggregate();
myModel
  .aggregatePaginate(myAggregate, options)
  .then(function (results) {
    console.log(results);
  })
  .catch(function (err) {
    console.log(err);
  });
// as Callback

var myModel = require('/models/samplemodel');

const options = {
    page: 1,
    limit: 10
};

var myAggregate = myModel.aggregate();
myModel.aggregatePaginate(myAggregate, options, function(err, results) {
	if(err) {
		console.err(err);
	else {
    	console.log(results);
	}
})
// Execute pagination from aggregate
const myModel = require('/models/samplemodel');

const options = {
    page: 1,
    limit: 10
};

const myAggregate = myModel.aggregate();
myAggregate.paginateExec(options, function(err, results) {
	if(err) {
		console.err(err);
	else {
    	console.log(results);
	}
})

Model.aggregatePaginate([aggregateQuery], [options], [callback])

Returns promise

Parameters

  • [aggregate-query] {Object} - Aggregate Query criteria. Documentation
  • [options] {Object}
    • [sort] {Object | String} - Sort order. Documentation
    • [offset=0] {Number} - Use offset or page to set skip position
    • [page] {Number} - Current Page (Defaut: 1)
    • [limit] {Number} - Docs. per page (Default: 10).
    • [customLabels] {Object} - Developers can provide custom labels for manipulating the response data.
    • [pagination] {Boolean} - If pagination is set to false, it will return all docs without adding limit condition. (Default: True)
    • [allowDiskUse] {Bool} - To enable diskUse for bigger queries. (Default: False)
    • [countQuery] {Object} - Aggregate Query used to count the resultant documents. Can be used for bigger queries. (Default: aggregate-query)
    • [useFacet] {Bool} - To use facet operator instead of using two queries. This is the new default. (Default: true)
  • [callback(err, result)] - (Optional) If specified the callback is called once pagination results are retrieved or when an error has occurred.

Return value

Promise fulfilled with object having properties:

  • docs {Array} - Array of documents
  • totalDocs {Number} - Total number of documents that match a query
  • limit {Number} - Limit that was used
  • page {Number} - Current page number
  • totalPages {Number} - Total number of pages.
  • offset {Number} - Only if specified or default page/offset values were used
  • hasPrevPage {Bool} - Availability of prev page.
  • hasNextPage {Bool} - Availability of next page.
  • prevPage {Number} - Previous page number if available or NULL
  • nextPage {Number} - Next page number if available or NULL
  • pagingCounter {Number} - The starting sl. number of first document.
  • meta {Object} - Object of pagination meta data (Default false).

Please note that the above properties can be renamed by setting customLabels attribute.

Sample Usage

Return first 10 documents from 100

const options = {
  page: 1,
  limit: 10,
};

// Define your aggregate.
var aggregate = Model.aggregate();

Model.aggregatePaginate(aggregate, options)
  .then(function (result) {
    // result.docs
    // result.totalDocs = 100
    // result.limit = 10
    // result.page = 1
    // result.totalPages = 10
    // result.hasNextPage = true
    // result.nextPage = 2
    // result.hasPrevPage = false
    // result.prevPage = null
  })
  .catch(function (err) {
    console.log(err);
  });

With custom return labels

Now developers can specify the return field names if they want. Below are the list of attributes whose name can be changed.

  • totalDocs
  • docs
  • limit
  • page
  • nextPage
  • prevPage
  • totalPages
  • hasNextPage
  • hasPrevPage
  • pagingCounter
  • meta

You should pass the names of the properties you wish to changes using customLabels object in options. Labels are optional, you can pass the labels of what ever keys are you changing, others will use the default labels.

If you want to return paginate properties as a separate object then define customLabels.meta.

Same query with custom labels


const myCustomLabels = {
  totalDocs: 'itemCount',
  docs: 'itemsList',
  limit: 'perPage',
  page: 'currentPage',
  nextPage: 'next',
  prevPage: 'prev',
  totalPages: 'pageCount',
  hasPrevPage: 'hasPrev',
  hasNextPage: 'hasNext',
  pagingCounter: 'pageCounter',
  meta: 'paginator'
};

const options = {
    page: 1,
    limit: 10,
    customLabels: myCustomLabels
};

// Define your aggregate.
var aggregate = Model.aggregate();

Model.aggregatePaginate(aggregate, options, function(err, result) {
if(!err) {
  // result.itemsList [here docs become itemsList]
  // result.itemCount = 100 [here totalDocs becomes itemCount]
  // result.perPage = 10 [here limit becomes perPage]
  // result.currentPage = 1 [here page becomes currentPage]
  // result.pageCount = 10 [here totalPages becomes pageCount]
  // result.next = 2 [here nextPage becomes next]
  // result.prev = null [here prevPage becomes prev]

  // result.hasNextPage = true [not changeable]
  // result.hasPrevPage = false [not changeable]
} else {
  console.log(err);
};

Using offset and limit

Model.aggregatePaginate(
  aggregate,
  { offset: 30, limit: 10 },
  function (err, result) {
    // result
  }
);

Using countQuery

// Define your aggregate query.
var aggregate = Model.aggregate();

// Define the count aggregate query. Can be different from `aggregate`
var countAggregate = Model.aggregate();

// Set the count aggregate query
const options = {
  countQuery: countAggregate,
};

Model.aggregatePaginate(aggregate, options)
  .then(function (result) {
    // result
  })
  .catch(function (err) {
    console.log(err);
  });

Global Options

If you want to set the pagination options globally across the model. Then you can do like below,

let mongooseAggregatePaginate = require("@omegion1npm/ipsam-ullam-rem");

let BookSchema = new mongoose.Schema({
  title: String,
  date: Date,
  author: {
    type: mongoose.Schema.ObjectId,
    ref: "Author",
  },
});

BookSchema.plugin(mongooseAggregatePaginate);

let Book = mongoose.model("Book", BookSchema);

// Like this.
Book.aggregatePaginate.options = {
  limit: 20,
};

Release Note

v1.0.7 - Upgrade to mongoose v8

v1.0.6 - Fixed exporting settings to global object.

v1.0.5 - Added meta attribute to return paginate meta data as a custom object.

v1.0.42 - Added optional countQuery parameter to specify separate count queries in case of bigger aggerate pipeline.

License

MIT