Skip to content

Commit b6483aa

Browse files
username1103hong3-inflab
authored andcommitted
feat: add token type value for in search operator
1 parent d5a03e2 commit b6483aa

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

core/src/main/kotlin/com/github/inflab/spring/data/mongodb/core/aggregation/search/InSearchOperatorDsl.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,26 @@ class InSearchOperatorDsl {
140140
document["value"] = value
141141
}
142142

143+
/**
144+
* Value or values to search.
145+
* Value can be either a single value or an array of values of only one of the supported BSON types and can't be a mix of different types.
146+
*
147+
* @param value Values to search.
148+
*/
149+
fun value(vararg value: String) {
150+
document["value"] = value.toList()
151+
}
152+
153+
/**
154+
* Value or values to search.
155+
* Value can be either a single value or an array of values of only one of the supported BSON types and can't be a mix of different types.
156+
*
157+
* @param value Values to search.
158+
*/
159+
@JvmName("valueStringIterable")
160+
fun value(value: Iterable<String>) {
161+
document["value"] = value
162+
}
163+
143164
internal fun build() = Document("in", document)
144165
}

core/src/test/kotlin/com/github/inflab/spring/data/mongodb/core/aggregation/search/InSearchOperatorDslTest.kt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,54 @@ internal class InSearchOperatorDslTest : FreeSpec({
298298
""".trimIndent(),
299299
)
300300
}
301+
302+
"should build a value by string" {
303+
// given
304+
val operator = `in` {
305+
value("value1")
306+
}
307+
308+
// when
309+
val result = operator.build()
310+
311+
// then
312+
result.shouldBeJson(
313+
"""
314+
{
315+
"in": {
316+
"value": [
317+
"value1"
318+
]
319+
}
320+
}
321+
""".trimIndent(),
322+
)
323+
}
324+
325+
"should build a value by multiple strings" {
326+
// given
327+
val operator = `in` {
328+
value("value1", "value2", "value3")
329+
}
330+
331+
// when
332+
val result = operator.build()
333+
334+
// then
335+
result.shouldBeJson(
336+
"""
337+
{
338+
"in": {
339+
"value": [
340+
"value1",
341+
"value2",
342+
"value3"
343+
]
344+
}
345+
}
346+
""".trimIndent(),
347+
)
348+
}
301349
}
302350

303351
"score" - {

0 commit comments

Comments
 (0)