1
+
1
2
import com.mongodb.client.model.Accumulators
2
3
import com.mongodb.client.model.Aggregates
3
4
import com.mongodb.client.model.Filters
@@ -33,7 +34,7 @@ internal class RetrieveDataTest {
33
34
34
35
@BeforeAll
35
36
@JvmStatic
36
- private fun beforeAll () {
37
+ fun beforeAll () {
37
38
runBlocking {
38
39
val paintOrders = listOf (
39
40
PaintOrder (1 , 10 , " purple" ),
@@ -47,7 +48,7 @@ internal class RetrieveDataTest {
47
48
48
49
@AfterAll
49
50
@JvmStatic
50
- private fun afterAll () {
51
+ fun afterAll () {
51
52
runBlocking {
52
53
collection.drop()
53
54
client.close()
@@ -59,13 +60,14 @@ internal class RetrieveDataTest {
59
60
fun basicFindTest () = runBlocking {
60
61
// :snippet-start: basic-find
61
62
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) }
63
65
// :snippet-end:
64
66
val expected = listOf (
65
67
PaintOrder (2 , 8 , " green" ),
66
68
PaintOrder (3 , 4 , " purple" ),
67
69
)
68
- assertEquals(expected, collection.find(filter) .toList())
70
+ assertEquals(expected, resultsFlow .toList())
69
71
}
70
72
71
73
@Test
@@ -82,13 +84,13 @@ internal class RetrieveDataTest {
82
84
),
83
85
Aggregates .sort(Sorts .descending(" qty" ))
84
86
)
85
- collection.aggregate<AggregationResult >(pipeline)
86
- .toList().forEach { println (it) }
87
+ val resultsFlow = collection.aggregate<AggregationResult >(pipeline)
88
+ resultsFlow.collect { println (it) }
87
89
// :snippet-end:
88
90
val expected = listOf (
89
91
AggregationResult (" green" , 19 ),
90
92
AggregationResult (" purple" , 14 )
91
93
)
92
- assertEquals(expected, collection.aggregate< AggregationResult >(pipeline) .toList())
94
+ assertEquals(expected, resultsFlow .toList())
93
95
}
94
96
}
0 commit comments