Code Monkey home page Code Monkey logo

aggregate-big-data-paginate's Introduction

mongoose-aggregate-big-data-paginate

this package will use for big data that mongo can't handle or count with aggregate.

Installation

npm install mongoose-aggregate-big-data-paginate
yarn add mongoose-aggregate-big-data-paginate

Usage

Adding the plugin to a schema,

var mongoose = require("mongoose");
var aggregatePages = require("mongoose-aggregate-big-data-paginate");

var schema = new mongoose.Schema({});

schema.plugin(aggregatePages);

var model = mongoose.model("Model", schema);

and then use model aggregatePage method,

// as Promise

var Model = require("/models/model");

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

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

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

Returns promise

Parameters

  • [aggregate-query] {Object} - Aggregate Query criteria. Documentation
  • [options] {Object}
    • [page] {Number} - Current Page (Defaut: 1)
    • [limit] {Number} - Docs. per page (Default: 10).

Return value

Promise fulfilled with object having properties:

  • docs {Array} - Array of documents
  • totalDocs {Number} - Total number of documents that match a query
  • totalPages {Number} - Total number of pages.
  • pages {Array} - All 5 pages

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

aggregate-big-data-paginate's People

Contributors

mr-hqq avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.