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

Allow for equality queries with respect to arrays or primitives [DATAMONGO-1897]

Open
#2,766 2 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

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

Description

Rafal Glowinski opened DATAMONGO-1897 and commented

Having a simple MongoDB document that contains an array:

{ 
    "type": "SOME_TYPE",
    "permissions" : ["A", "B", "C"]
}

I would like to find all documents that match this MongoDB query:

{ "type": "SOME_TYPE", "permissions": { $elemMatch: { $eq: "B" } } }

Currently, I have to use this construct:

Criteria.where("type").is("SOME_TYPE").and("permissions").elemMatch(new Criteria().in("B"))

which translates to:

{ "type": "SOME_TYPE", "permissions": { $in: ["B"] } }

What is missing, in my opinion, is a method 'eq' on Criteria, that would let us write:

Criteria.where("type").is("SOME_TYPE").and("permissions").elemMatch(new Criteria().eq("B"))

Attachments:

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.