spring-projects / spring-projects/spring-data-mongodb
Allow for equality queries with respect to arrays or primitives [DATAMONGO-1897]
Open
@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:
- DATAMONGO-1897.patch (3.02 kB)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.