db.Employee.find().sort({Employeeid:-1}).forEach(printjson)
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
}
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