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

sort mongoose response

Blah.find({}).sort({date: -1}).execFind(function(err,docs){
//code
});

-1 for descending & 1 for ascending
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 :: jquery table each rows with class 
Javascript :: change span value javascript 
Javascript :: nodejs javascript heap out of memory 
Javascript :: nodejs request 
Javascript :: nextjs layout 
Javascript :: mongoose schema cast decimals 
Javascript :: js addeventlistener 
Javascript :: How to lock Orientation for a particular screen in ios in react native 
Javascript :: reduce array to object javascript 
Javascript :: create function replace all n javescript 
Javascript :: JSON Web Token (JWT) set expire time in node js 
Javascript :: vuex add multiple payload to mutation 
Javascript :: showing bootstrap modal after a delay 
Javascript :: javascript cors error 
Javascript :: jshint esversion: 6 
Javascript :: how to find largest number in array in javascript 
Javascript :: Get LocalStorage from WebView react native 
Javascript :: Too long with no output (exceeded 10m0s): context deadline exceeded 
Javascript :: javascript change css 
Javascript :: javascript easiest way to get second parent 
Javascript :: python json.dumps pretty print 
Javascript :: for object 
Javascript :: javascript array move element one position 
Javascript :: filereader check file type 
Javascript :: round js 
Javascript :: javascript create array with null values 
Javascript :: fetch catch 
Javascript :: document.on chenage jquer 
Javascript :: input radio trigger select jquery 
Javascript :: express receive post 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =