Skip to content

RestQuery.each override queries constraints on objectId field #5274

Closed
@percypyan

Description

@percypyan

Issue Description

When checking the roles of a user during a query, the relation constraints { users: { __type: 'Pointer', className: '_User', objectId: 'OJ1uFj4U8C' } } on the _Role class is transformed into { objectId: { '$in': [ ...objectIds... ] } }. The problem is that for each iteration done if the request isn't finished, the objectId constraint is replace by { objectId: { '$gt': 'anId' } }. So the original constraint is lost after the first iteration (if there are more _Role objects than the limit), causing the retrieval of all roles in the database.

The culprit line is src/RestQuery.js:217.

restWhere.objectId = {
    $gt: results[results.length - 1].objectId
};

should be

restWhere.objectId = Object.assign({}, restWhere.objectId, {
    $gt: results[results.length - 1].objectId
});

Steps to reproduce

Use RestQuery.prototype.each with a relational query and a limit of one.
(.i.e. { numbers: { __type: 'Pointer', className: 'Number', objectId: object2.id } })
If the collection of the related objects contains more than the requested object, you should get more results.

See test on #5276 for detailed test.

Expected Results

Should only retrieve the queried object.

Actual Outcome

Return more object than the queried object.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 3.1.1
    • Operating System: MacOS locally and unknown on Heroku
    • Hardware: Macbook Pro Late 2014 locally
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Heroku
  • Database

    • MongoDB version: 3.6.9
    • Storage engine: [FILL THIS OUT]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab

Logs/Trace

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