Skip to content

Commit 84cec34

Browse files
committed
use collect on flow
1 parent 2a18b7b commit 84cec34

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

examples/src/test/kotlin/RetrieveDataTest.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import com.mongodb.client.model.Accumulators
23
import com.mongodb.client.model.Aggregates
34
import com.mongodb.client.model.Filters
@@ -33,7 +34,7 @@ internal class RetrieveDataTest {
3334

3435
@BeforeAll
3536
@JvmStatic
36-
private fun beforeAll() {
37+
fun beforeAll() {
3738
runBlocking {
3839
val paintOrders = listOf(
3940
PaintOrder(1, 10, "purple"),
@@ -47,7 +48,7 @@ internal class RetrieveDataTest {
4748

4849
@AfterAll
4950
@JvmStatic
50-
private fun afterAll() {
51+
fun afterAll() {
5152
runBlocking {
5253
collection.drop()
5354
client.close()
@@ -59,13 +60,14 @@ internal class RetrieveDataTest {
5960
fun basicFindTest() = runBlocking {
6061
// :snippet-start: basic-find
6162
val filter = Filters.and(Filters.gt("qty", 3), Filters.lt("qty", 9))
62-
collection.find(filter).toList().forEach { println(it) }
63+
val resultsFlow = collection.find(filter)
64+
resultsFlow.collect { println(it) }
6365
// :snippet-end:
6466
val expected = listOf(
6567
PaintOrder(2, 8, "green"),
6668
PaintOrder(3, 4, "purple"),
6769
)
68-
assertEquals(expected, collection.find(filter).toList())
70+
assertEquals(expected, resultsFlow.toList())
6971
}
7072

7173
@Test
@@ -82,13 +84,13 @@ internal class RetrieveDataTest {
8284
),
8385
Aggregates.sort(Sorts.descending("qty"))
8486
)
85-
collection.aggregate<AggregationResult>(pipeline)
86-
.toList().forEach { println(it) }
87+
val resultsFlow = collection.aggregate<AggregationResult>(pipeline)
88+
resultsFlow.collect { println(it) }
8789
// :snippet-end:
8890
val expected = listOf(
8991
AggregationResult("green", 19),
9092
AggregationResult("purple", 14)
9193
)
92-
assertEquals(expected, collection.aggregate<AggregationResult>(pipeline).toList())
94+
assertEquals(expected, resultsFlow.toList())
9395
}
9496
}

source/examples/generated/RetrieveDataTest.snippet.aggregation-find.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ val pipeline = listOf(
99
),
1010
Aggregates.sort(Sorts.descending("qty"))
1111
)
12-
collection.aggregate<AggregationResult>(pipeline)
13-
.toList().forEach { println(it) }
12+
val resultsFlow = collection.aggregate<AggregationResult>(pipeline)
13+
resultsFlow.collect { println(it) }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
val filter = Filters.and(Filters.gt("qty", 3), Filters.lt("qty", 9))
2-
collection.find(filter).toList().forEach { println(it) }
2+
val resultsFlow = collection.find(filter)
3+
resultsFlow.collect { println(it) }

0 commit comments

Comments
 (0)