Skip to content

_getQueryModifier not applied on service _find with pagination #421

Open
@arkabase

Description

@arkabase

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions