apache / apache/grails-core

GPMONGODB-406 nested criteria produces wrong query

Open
#14,664 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-mongodb
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

when building a criteria like below the mongo query that gets created is incorrect. the 'or' is ignored completely

`def criteria = Class.createCriteria()
criteria.list(){
eq("field1", "value1")
field2{
isNull("subfield2")
}
or {
field2{
'in'("subfield2.subsubfield", list)
}
eq("field3","value3")
}
}`
produces:
`{
"$and":[
{"field1":"value1"}
{"field2.subfield2":null}
{"field2.subfield2.subsubfield":{"$in":["val1","val2","val3","val4"]}}
{"field3":"value3"}
]
}`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the nested criteria example from the issue and inspect the MongoDB criteria query-generation path. Verify the generated query for the nested or block; done means the or conditions remain grouped correctly instead of being added unconditionally to the top-level $and.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.