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]
- [freeTextSearch]
- [sortStage]
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
}
}
}