Skip to content

$in on array fields #3528

Open
Open
@SledgeHammer01

Description

@SledgeHammer01

Using spring-data-mongodb 3.1.2, my repo looks like:

@Repository
public interface AirBnbRepository extends  MongoRepository<Listing, String>,
										   QuerydslPredicateExecutor<Listing> {
}

The doc has a field thats a string array:

"amenities": ["TV", "Cable TV",

I'm trying to build a dynamic query with dsl, so something like:

BooleanBuilder builder = new BooleanBuilder();

if ((amenities != null) && (amenities.length > 0))
builder.and(QListing.listing.amenities.in(amenities));


This resulted in: find using query: { "amenities" : ["Wifi2"]}, which is wrong since its missing the whole $in portion. I stepped through the code and found there is a code path in there that if you have only 1 element, you change it to an eq. So I tried 2. I also tried bypassing the whole thing with:

builder.and(Expressions.booleanOperation(Ops.IN, QListing.listing.amenities, ConstantImpl.create(amenities)));

and got the same result. No $in.

How can we get the $in to work on an array with a dynamic query at runtime? I do also need to have pageable support :).

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions