parse-community / parse-community/parse-server

Relational query with .limit() and descending order does not work as expected.

Open
#9,600 2 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

Issue Description

I have two parse classes User and Post. The user class has relation named posts containing Post objects. When i do
the following query

user.relation("posts", className: Post.className) .query(Post()) .limit(5) .order(.descending("createdAt"))

i got less than 5 objects nevertheless the user has more than 5 posts.

Steps to reproduce
  1. Creates 6 posts, let say post 1, post 2, ..., post 6. Post[i] is created before Post[i+1].
  2. Delete the last created post (post 6).
  3. Then run the provided query with limit 5.
Actual Outcome

The query returns post 5, post 4, post 3 and post 2 (total of 4 posts).

Expected Outcome

My expectation is that the query will omit the deleted object and return the first 5 available objects - post 5 up to post 1.
This happens because the join table representing the relation keeps the id of the deleted object. The limit operator gives 5 object ids including the id of the deleted object. I consider this a bug.

Server

  • Parse Server version: 4.10.4
  • Operating system: macOS
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local/Heroku

Database

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

Client

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

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 with the relational query chain using relation("posts"), query(), limit(), and descending order, then trace how the MongoDB join table IDs are selected and filtered. Reproduce the six-post case and verify that deleting the newest post still returns five available posts in descending createdAt order.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.