Here is my mongoose code which does sorting
And pagination. Here when i am removing sorting
or adding other type of sort no result is coming.
And i have 3000 documents in db
res = await Question.find(filters)
.sort({'_id': "-1"})
.skip(args.skip ? parseInt(args.skip) : 0)
.limit(args.limit ? parseInt(args.limit) : 100)
.exec();
Please take a look
2
Answers
Replace this:
With:
The
.sort()
command accept as Objects or strings as parameters.On the Object syntax the values allowed are
asc
,desc
,ascending
,descending
,1
, and-1
string syntax
Note: You don’t need the
.exec()
part when you are using promises