spring-projects / spring-projects/spring-data-mongodb

Custom Mongo queries inexplicably return zero results after upgrading to 3.0.8.RELEASE or later (spring-boot dep mgmt: 2.3.10.RELEASE or later)

Open
#3,658 6 comments 0 reactions 1 assignee View on GitHub

@mp911de is already working on this.

Since Jun 7, 2021.

type: regression
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I've created a repo to demonstrate the issue, at https://github.com/oliverlockwood/mongodb-issue-demonstration, based on following the guidelines at https://spring.io/guides/gs/accessing-data-mongodb/.

That repo has a clear README but I'll highlight the main points here as well.

  • In terms of environment, I have a local Docker container running MongoDB version 4.2.14, mapping ports 27017 and 28017.
  • The Customer model class contains a map field, like: public Map<String, DataValue> additionalData;
  • There are custom read/write converters configured; we persist the map as an array of (name, value) tuples, viz:
    Screenshot 2021-05-26 at 14 18 26
  • We have a custom repository implementation which allows dynamic queries to be specified (in our real use-case, via REST query payloads; in the example repo, via hard-coding in the run() method)
  • The custom Mongo query we generate in the application (regardless of spring-data-mongodb version) is logged out as:
    Query: { "$and" : [{ "additionalData.name" : "a"}, { "additionalData.value" : "b"}]}, Fields: {}, Sort: {}
  • With spring-boot version 2.3.9.RELEASE (therefore spring-data-mongodb version 3.0.7.RELEASE) an entry is found as expected by this query
  • With spring-boot version 2.3.10.RELEASE or higher (therefore spring-data-mongodb version 3.0.8.RELEASE or higher) no results are found
  • Directly querying Mongo via the console, i.e.
    db.getCollection('customer').find({ "$and" : [{ "additionalData.name" : "a"}, { "additionalData.value" : "b"}]})
    finds an entry as expected

I therefore conclude this is a regression in spring-data-mongodb, but I can't for the life of me figure out why it stops returning results.

I hope this in combination with the repo is enough context for you to investigate; please advise if you need me to provide any more information.

Many thanks!

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.