matrei opened a new pull request, #16362: URL: https://github.com/apache/grails-core/pull/16362
## Summary A `Map` passed as a criterion value in GORM for MongoDB was placed into the BSON query document unchanged. MongoDB interprets a value document whose keys start with `$` as an operator expression rather than as a value, so such a map was not compared as a value. This change validates criterion values before the query document is built: - `BsonQuery.validateCriterionValues` runs for every criterion at the top of both `populateBsonQuery` loops and of `MongoQuery.populateMongoQuery`, before the custom type branch, and recurses through junctions. It covers the value of every `PropertyCriterion`, both `Between` bounds and every `In` element, so enum and other custom typed properties and negated criteria are included. - A `Map` value is rejected with `InvalidDataAccessResourceUsageException` when a key at any depth starts with `$`. The walk descends into nested maps, collections and arrays and is capped at MongoDB's 100 level nesting limit, so a self-referential value is reported as invalid. - A `Map` without such keys is still sent as a literal subdocument comparison, so exact matches on `Map` properties, dotted paths, array elements and schemaless attributes are unchanged. - Geospatial and subquery criteria carry shape documents or nested queries by design and are exempt. - The native `find(Bson)` and collection APIs are untouched and remain the place for operator queries that GORM does not express. ## Tests - `BsonQuerySpec` (no database) is data-driven over every affected criterion, including `idEq`, negated and nested criteria, a bson `Document` value, `$` keys at every depth and as a GString key, self-referential map, list and array values, and `$`-free maps passing through as literals. - New `MapCriterionValueSpec` exercises the public APIs end to end, including every query form on an enum property, and pins the cases that must keep working. ## Documentation - MongoDB querying guide: new "Criterion values" section. - Upgrade notes: new entry describing the behaviour change. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
