Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not accounting for options passed in counting documents #186

Open
molaeiali opened this issue Dec 23, 2022 · 0 comments
Open

Not accounting for options passed in counting documents #186

molaeiali opened this issue Dec 23, 2022 · 0 comments

Comments

@molaeiali
Copy link

Describe the bug
There is an option named strictQuery in mongoose, that will clean the query from fields that do not exist in the schema.

Say we have a users collection like this:

users { name: String }

Notice that the users schema only has a name property and not an email property, Now if I try:

Users.find({ email: 'something'})

and strictQuery is true for the UserSchema, it will remove the email parameter from the query and the query will become {} so it returns all documents in the Users collection.

if strictQuery is false, it will not clean the query from non-existing fields, so it will return nothing.

https://mongoosejs.com/docs/guide.html#strictQuery

Problem is, when strictQuery is sent false to the paginate function, it will truly return noting in docs property, but totalDocs value will not become affected by strictQuery and returns a non-zero value.

To Reproduce

paginate(...., options: { strictQuery: false });

Expected behavior
If there is no value in docs property, totalDocs should be 0 as well. right now, docs and totalDocs are not matched. (not only for 0 value, but it can also be 1 in docs and totalDocs be 3 or something).

Output Example

 {
        "docs": [],
        "totalDocs": 2,
        "limit": 10,
        "totalPages": 1,
        "page": 1,
        "pagingCounter": 1,
        "hasPrevPage": false,
        "hasNextPage": false,
        "prevPage": null,
        "nextPage": null
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant