1.0.7 • Published 1 year ago

mongo-common-function v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Mongo Query some common function

Installation

First install Node.js and MongoDB. Then:

$ npm install mongo-common-function

Importing

// Using Node.js `require()`
const mongoFunctions = require('mongo-common-function');

// Using ES6 imports
import mongoFunctions from 'mongo-common-function';

Function Docs

paginationPipeBuilder

Add after the last Aggragtion Pipeline to get Pagination in the mongodb or mongoose aggregation

aggPipe: Existing Pipeline of your code. limit: Page shown the rows. Limit as null condsider as all data will came on first page. page: Page Number start with 1.

// Using Node.js `require()`
//paginationPipeBuilder(aggPipe, limit, page);
const { paginationPipeBuilder } = require('mongo-common-function');

// Dummy input
paginationPipeBuilder({$match:{$eq:/**/}}, 5, 1);

//Dummy output
{ 
    pipeline: {
        "data": [],
        "data_info": {
            "totalCount": 0,
            "page": {
                "size": 0,
                "index": 1,
                "lastPage": true
            },
            "totalPage": 0
        }
    }, 
    staticPaging: {
            "data": [],
            "data_info": {
                "totalCount": 0,
                "page": {
                    "size": 0,
                    "index": 1,
                    "lastPage": true
                },
                "totalPage": 0
            }
        } 
    }