Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose find sort

Post.find({}).sort('test').exec(function(err, docs) { ... });
Post.find({}).sort([['date', -1]]).exec(function(err, docs) { ... });
Post.find({}).sort({test: 1}).exec(function(err, docs) { ... });
Post.find({}, null, {sort: {date: 1}}, function(err, docs) { ... });
Comment

mongoose sort

  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

Mongoose sort

// sort by "field" ascending and "test" descending
query.sort({ field: 'asc', test: -1 });

// equivalent
query.sort('field -test');
Comment

PREVIOUS NEXT
Code Example
Javascript :: get list of filenames in folder 
Javascript :: merge in mongodb 
Javascript :: schema mongoose 
Javascript :: if else react render in jsc 
Javascript :: react show view based on role permission 
Javascript :: react qurery jest test mock queryClientProvider 
Javascript :: opacity material ui 
Javascript :: onselect in zebra datepicker 
Javascript :: js.l2 
Javascript :: alert message 
Javascript :: slideshow react npm 
Javascript :: twhat is a js promise 
Javascript :: react-bootstrap problem-import new version 
Javascript :: add points to numbers js 
Javascript :: How to have hotjar in react-hotjar 
Javascript :: make a if in jsx 
Javascript :: check unique object in array javascript site:stackoverflow.com 
Javascript :: image load fail event html 
Javascript :: javascript Use clearTimeout() Method 
Javascript :: the rest operator javascript 
Javascript :: change dictionary value in React js 
Javascript :: python dictionary setdefault in javascript 
Javascript :: append array to array javascript 
Javascript :: dayofmonth mongodb 
Javascript :: react rating stars component 
Javascript :: javascript export multiple function 
Javascript :: get ip address with js 
Javascript :: make alphabet js 
Javascript :: destructuring 
Javascript :: js similar jquery document ready 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =