MorphiaOrg / MorphiaOrg/morphia

datastore.find(Class, FindOptions) does not apply FindOptions (limit/skip/sort not respected)

Open
#3,514 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Waiting for Response
Dominant language
Java
Stars
1.7k
Forks
449
Avg merge
7m
Merged PRs (30d)
10

Description

Describe the bug
I’m using Morphia 2.5.0, and I've encountered an issue when following the suggested way to apply pagination and sorting using:

However, it appears that the FindOptions passed in this way are not actually applied. For example, limit(), skip(), and sort() seem to be ignored. The query returns all results without applying the intended pagination or sorting behavior.

To Reproduce
Using the find with options
`
FindOptions options = new FindOptions()
.limit(10)
.skip(20)
.sort(Sort.descending("createdAt"));

List results = datastore.find(MyClass.class, options)
.filter(Filters.eq("status", "ACTIVE"))
.stream() // or .toList()
.toList();
`

Expected: returns 10 items, skipping 20, sorted by createdAt descending.
Actual: returns all items with no pagination or sorting applied.

Meanwhile, the old (now deprecated) usage still works correctly:
datastore.find(MyClass.class) .filter(Filters.eq("status", "ACTIVE")) .stream(options) .toList();

** Please complete the following information: **

  • Server Version: 7.0.21
  • Driver Version: 5.5.1
  • Morphia Version: 2.5.0
    -- From dependency "dev.morphia.morphia:morphia-core:2.5.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 at the datastore.find(MyClass.class, options) entry point and compare it with the deprecated datastore.find(MyClass.class).stream(options) path. Reproduce the issue with limit(10), skip(20), and descending createdAt, then add or update coverage for filtering, pagination, and sorting so the new API matches the expected results.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.