Skip to content

Incorrect handling of nested path in paginatedFields causes path collision in newer versions of mongoose #373

@gotenxds

Description

@gotenxds

Hi, in the findWithPagination the first line checks if the paginatedField is in the projection, otherwise it is marked for removal, similarly inside the sanitizeParams function if the fields is not in the projection it will add it to the projection.

This works when the field is an atomic field or when the field is not being queried at all but fails when the fields is an nested field that is being requested in the projection.

For example for the schema

User {
 location: {
   city: string
 }
}

if the projection is {location: 1}

and the paginated field is location.city
than, in the first check, no location.city is not inside the projection so we should delete it at the end (which is false)
and for the sanitizeParams, no location.city is not inside the projection so we should add it.

Adding it to the projection in older versions on mongoose is fine, but in recent versions this causes a Path collision issue as we are trying to project both location and location.city

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