Added GET API with the corresponding route and statics method which return all questions from DB as a JSON object:
/api/question/api/question?sortby=date/api/question?sortby=date&order=1/api/question?sortby=date&order=-1
The parameter sortby can take values date, views, scores, and n_answers; order is either 1 or -1. Default values are date and -1 respectively.
The population method is used to refer ids in the Questions collection to names in the User collection (It requires also Users in api.js which is not used explicitly!). It means that in the returned JSON document author is an object with properties _id and name.
To test I created a DB on mlab and added a few documents (Ipsum...), so change in .env the variable MONGODB_URI (to get uri, login and password see our Slack channel) to connect to it.
/api/question
/api/question?sortby=date
/api/question?sortby=date&order=1
/api/question?sortby=date&order=-1
sortby
can take valuesdate
,views
,scores
, andn_answers
;order
is either1
or-1
. Default values aredate
and-1
respectively.Questions
collection to names in theUser
collection (It requires alsoUsers
in api.js which is not used explicitly!). It means that in the returned JSON documentauthor
is an object with properties_id
andname
.