Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 854 Bytes

2020-03-17-spring-data-mongo-in-query.markdown

File metadata and controls

27 lines (18 loc) · 854 Bytes
layout title date comments categories
post
How To: perform an 'in' query with mongo and spring-data
2020-03-17 08:00:00 +0000
true
developers
spring
spring-data

Unfortunately it looks like spring-data will not autowire up queries that will perform an in query under the hood.

Out of the box, you can query for ids using a CrudRepository:

fun findAllById(ids: Iterable<ID>) : Iterable<Entity>

Spring will also automatically wire up simple queries like:

fun findAllByPropertyId(propertyId: String) : Iterable<Entity>

What it won't do is wire up fun findAllByPropertyId(propertyIds: Iterable<ID>) : Iterable<Entity>.

You must to annotate the interface method with the query you want it to perform.

@Query("{propertyId: { \$in: ?0 }}")
fun findAllByPropertyId(propertyIds: Iterable<ID>) : Iterable<Entity>