Skip to content

Criteria with is and another filter for the same field creates invalid query doucment #4850

Closed
@fstorz

Description

@fstorz

Description
When using the method is in the Criteria class together with any other filter element (without the and operator), then the created filter document is invalid.

Relevant code:

if (!NOT_SET.equals(isValue)) {
queryCriteria.put(this.key, this.isValue);
queryCriteria.putAll(document);
} else {

How to reproduce
The following Criteria object

Criteria.where("name")
    .is(123)
    .type(JsonSchemaObject.Type.INT_64)

creates

{"name": 123, "$type": ["long"]}

which is invalid.

Using the following Criteria object

Criteria.where("name")
    .in(123)
    .type(JsonSchemaObject.Type.INT_64)

creates

{"name": {"$in": [123], "$type": ["long"]}}

which is valid and more or less the same, just does not use "is".

Expected
When using is in combination with other filters for the same property, all filters should be combined into a sub-document using $eq for the equality check of the value provided to the is method.

Criteria.where("name")
    .is(123)
    .type(JsonSchemaObject.Type.INT_64)

should create

{"name": {"$eq": 123, "$type": ["long"]}}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions