express request
express response
mongoose model
query filter object
fields to populate
fields to search in for q query
Object in response like
{
"status": "success",
"data": Array of documents,
"pageInfo": {
currentPage: // current page number,
perPage: // per page document count,
pageCount: // total page count,
skipCount: // skip count,
itemCount: // total document count,
hasNextPage: // true if has next page,
hasPreviousPage: // true if has previous page,
}
}
Generated using TypeDoc
Throws
error if mongoose error, in this case it will send response with status 500, and error message
Example
Example
if you want to populate fields in response
Example
if you want to search in specific fields
Example
your custom query filter object, you can also modifiy the filter object based on your needs or user role etc
Query
pass query object, it will return documents where the field value is equal to the query value, you can pass multiple query objects
make sure when you passing query object, use same field name as in your schema
pass inList query object, it will return documents where the field value is in the list
pass notInList query object, it will return documents where the field value is not in the list
pass q query to search in all fields
query with pagination, it will return 10 documents from page 1
query with sort DESC, it will sort the documents by createdAt field in descending order
query with sort ASC, it will sort the documents by createdAt field in ascending order
query with fields, it will return only the selected fields
pass mongo compatible query object, when your query is not supported by the above query objects