Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongodb sort query

db.Employee.find().sort({Employeeid:-1}).forEach(printjson)
Comment

mongoDB 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

order by mongodb

db.people.find( { status: "A" } ).sort( { user_id: 1 } )
db.people.find( { status: "A" } ).sort( { user_id: -1 } )

-- sql
SELECT *
FROM people
WHERE status = "A"
ORDER BY user_id ASC

SELECT *
FROM people
WHERE status = "A"
ORDER BY user_id DESC
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript get last object in foreach loop 
Javascript :: if text exists in element using javascript 
Javascript :: momentjs format date 
Javascript :: javascript execute function by string name 
Javascript :: create react app with vite 
Javascript :: js hexadecimal 
Javascript :: angularjs find and update object in array 
Javascript :: discord.js v13 if dm 
Javascript :: window.addeventlistener 
Javascript :: copy text on click 
Javascript :: parse time in javascript 
Javascript :: uppercase javascript using function 
Javascript :: minify html using javascript 
Javascript :: regular expression characters 
Javascript :: png to base64 javascript 
Javascript :: how to poll efficiently in javascript 
Javascript :: discord.js checking channel permissions 
Javascript :: usereducer hook 
Javascript :: how to add items in an array in js 
Javascript :: using async function in useeffect 
Javascript :: regex start line 
Javascript :: create fooer on print page with jquery 
Javascript :: mongoose delete 
Javascript :: mui date picker width 
Javascript :: downgrade node version 
Javascript :: how to delete an element of an array in javascript 
Javascript :: read json using fs 
Javascript :: js add array to array 
Javascript :: react native new project mac 
Javascript :: console log return from async 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =