_getQueryModifier not applied on service _find with pagination
arkabase opened this issue · comments
ArkaBASE commented
In service.js (line 104) method _getQueryModifier is applied to mongoose query q :
this._getQueryModifier(params)(q, params);
but when pagination is active (lines 124+), a new query is used to count the documents instead of q :
if (paginate && paginate.default) {
return model.where(query)[this.useEstimatedDocumentCount ? 'estimatedDocumentCount' : 'countDocuments']()
.session(params.mongoose && params.mongoose.session).exec().then(executeQuery);
}
_getQueryModifier is not applied to this new query, and so the total can be false if the queryModifier function filters the original query.
This part should be :
if (paginate && paginate.default) {
const w = model.where(query);
this._getQueryModifier(params)(w, params);
return w[this.useEstimatedDocumentCount ? 'estimatedDocumentCount' : 'countDocuments']()
.session(params.mongoose && params.mongoose.session).exec().then(executeQuery);
}