Skip to content

Commit

Permalink
feat: change count of searching result method
Browse files Browse the repository at this point in the history
- count({}), use the estimatedDocumentCount() function
instead.
Otherwise, use the countDocuments() function instead.
  • Loading branch information
Chinlinlee committed Feb 7, 2022
1 parent bf4b3a0 commit 2b9751b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/FHIRApiService/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ module.exports = async function(req, res,resourceType,paramsSearch) {
docs = docs.map(v => {
return v.getFHIRField();
});
let count = await mongodb[resourceType].countDocuments(queryParameter);
let count = 0;
if (_.isEmpty(queryParameter)) {
count = await mongodb[resourceType].estimatedDocumentCount();
} else {
count = await mongodb[resourceType].countDocuments(queryParameter);
}
let bundle = createBundle(req, docs, count, paginationSkip, paginationLimit, resourceType);
res.header('Last-Modified', new Date().toUTCString());
return doRes(200 , bundle);
Expand Down

0 comments on commit 2b9751b

Please sign in to comment.