Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose pagination with total count Code Example

  let limit = parseInt(req.body.limit) || 10
  let page = parseInt(req.body.page) - 1 || 0
  var query = {};
  let users = await Users.find({}).sort({ createdAt: -1 }).skip(limit * page).limit(limit).select("fields you want to select separated by space")
  const count = await Users.countDocuments(query);
  let obj = {
    Users: users,
    total: count,
    limit: limit,
    page: page + 1
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: js know size of screen displayed 
Javascript :: vue call method after render 
Javascript :: jquery get 2nd child 
Javascript :: moment get day 
Javascript :: cypress check element have attribute 
Javascript :: sequelize change column 
Javascript :: queryselectorall javascript images in list 
Javascript :: mongoose update push 
Javascript :: css class list 
Javascript :: typescript express next middleware type 
Javascript :: request animation frame 
Javascript :: lowercase to uppercase in javascript 
Javascript :: mongoose unique validator 
Javascript :: javascript date format mm/dd/yyyy 
Javascript :: react blur background 
Javascript :: poll in javascript 
Javascript :: promise.race 
Javascript :: usereducer example 
Javascript :: select selected option value jquery 
Javascript :: react native navigation change header title 
Javascript :: list of higher-order functions javascript 
Javascript :: count javascript 
Javascript :: js code sample 
Javascript :: modulo operator in javascript 
Javascript :: javascript array delete first element 
Javascript :: remove duplicate value from array 
Javascript :: convert array to object 
Javascript :: add array to array js 
Javascript :: javascript create object key from variable 
Javascript :: vuejs vscode unbound breakpoint 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =