parse-community / parse-community/parse-server

Query with $relatedTo has some critical issues

Open
#8,532 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

New Issue Checklist
Issue Description

Build a parse query that uses $relatedTo and count, in order to get results and total count.
Parse uses the "Limit" parameter value in order to limit the $relatedTo query, this causes a incorrect count value to be returned.

Steps to reproduce
await Parse.Query.fromJSON('ExampleClass',
{
    "limit":15,
    "skip:"0",
    "where": {
        "$relatedTo": {
            "object": {
                "__type": "Pointer",
                "className": "RelatedClass",
                "objectId": "someObjectId"
            },
            "key": "examples"
        },
    }
})

Actual Outcome

result = depends on order desc or asc, if valid document is in range (0-15) it will show, but if not it will not.
count = returns lower count than actual count of valid documents (14 when there are 33 for example)

Expected Outcome

result = should return all documents that match upto limit so paging can work properly.
count = should return total count of all matching documents, regardless of limit.

Environment

latest, 5.4.3

Server

  • Parse Server version: 5.4.3
  • Operating system: ubuntu
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): monogdb
  • Database version: 5.0
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): digitalocean

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): web
  • SDK version: rest

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Parse.Query.fromJSON entry point and trace how $relatedTo handles limit, skip, results, and count against MongoDB. Reproduce the case with 33 matching documents and a limit of 15; done means paging returns the limited matching results while count reports all matching documents.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
api, backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.