Skip to content

Unable to compare two double columns within the same collection in Mongodb #1421

@kamilkrzywanski

Description

@kamilkrzywanski

Ported from: querydsl/querydsl#3916

Observed vs. expected behavior

I have a Collection in Mongodb with 2 fields, 'totalStock' and 'minStock',
I want to get all data where totalStock <= minStock by

QProduct product = QProduct.product;
BooleanBuilder booleanBuilder = new BooleanBuilder();
booleanBuilder.and(product.totalStock.loe(product.minStock));
productMongoRepository.findAll(booleanBuilder, pageable)

But the results returned empty, which should have expected data when checking through my Mongodb data explorer.

Below is the productMongoRepository class that extends MongoRepository and QueryDSLPredicateExecutor:

public interface ProductMongoRepository extends MongoRepository<Product,String>, QuerydslPredicateExecutor {
}

Both values of the POJO are in 'double' values:

public class Product {
...
    private double totalStock;
    private double reservedStock;
    private double minStock;
}

Environment
localhost, mongodb
Querydsl version: 5.1.0
Querydsl module: querydsl-apt, querydsl-mongodb
Database: MongoDB
JDK: 21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions