Spring Data MongoRepository between for int values

orirab

having a class such as (this is kotlin, but the code is very understandable):

@Repository
interface ScoresRepository : MongoRepository<Score, String> {
    fun countAllByScoreIsBetween(min: Int, max: Int): Int
}

@Document
data class Score(
    @Id var score: Int,
)

Is the between inclusive or exclusive? That is, if I have scores 1-10, and I called: countAllByScoreIsBetween(3,6) would I get 4 or 2? or maybe something else - bottom is inclusive and top is exclusive?

orirab

Tests (with testcontainers) show this:

@Autowired
lateinit var scoresRepository: ScoresRepository

@Test
fun test() {
    for (i in 1..10) {
        scoresRepository.save(Score(score = i))
    }

    val count = scoresRepository.countAllByScoreIsBetween(3, 6)

    assertThat(count).isEqualTo(2)
}

So as far as I see, both params are not included. That is, Between means everything between the values, not including the values themselves.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What's the difference between Spring Data's MongoTemplate and MongoRepository?

Spring data mongorepository, find by inner object field

Spring Data Mongodb & Spring Boot - autowiring MongoRepository from Mongolab

Keep reference data in application memory in spring application (spring MongoRepository)

Spring Data MongoRepository save(T) not working... sometimes

Custom @Query annotated method for update query with spring data MongoRepository

Custom @Query annotated method for update query with spring data MongoRepository

Spring Data- MongoRepository : Can we have binary type as the _id?

Spring Data MongoRepository Saving Objects with Differing Numbers of Fields

MongoRepository query for between dates

Spring MongoRepository is Null

Autowire MongoRepository in Spring MVC

Fetching all Mongo documents based on different combinations of values of same query parameters using Spring MongoRepository

Java Spring : MongoRepository count() and findAll()

Spring Boot MongoRepository ignoring validation

Spring MongoRepository, where to catch the exception?

Resolve variable name for MongoRepository in Spring

MongoRepository JSON Date Query (Spring)

Spring MongoRepository is updating or upserting instead of inserting

could not found bean for MongoRepository (Spring Boot)

findByParentIdDeletedIsFalse like query in Spring Boot MongoRepository

Spring MongoRepository query adding _class field to queries

Spring MongoRepository very slow to convert POJO

Is saveAll() of MongoRepository inserting data in one bulk?

Difference between "Data" and "Values" in R

extracting data based on values between

Initializing an int variable as in between 2 values in Java

Spring data date between query

Avoid fractional values in int fields in spring boot