Skip to content

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

@wasut-bst

Description

@wasut-bst

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"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions