11
22import com.mongodb.MongoNamespace
3- import com.mongodb.client.model.*
4- import com.mongodb.client.model.Accumulators.*
5- import com.mongodb.client.model.Aggregates.*
6- import com.mongodb.client.model.Sorts.ascending
3+ import com.mongodb.client.model.Accumulators
4+ import com.mongodb.client.model.Aggregates
5+ import com.mongodb.client.model.BucketAutoOptions
6+ import com.mongodb.client.model.BucketGranularity
7+ import com.mongodb.client.model.BucketOptions
8+ import com.mongodb.client.model.Facet
9+ import com.mongodb.client.model.Field
10+ import com.mongodb.client.model.Filters
11+ import com.mongodb.client.model.GraphLookupOptions
12+ import com.mongodb.client.model.IndexOptions
13+ import com.mongodb.client.model.Indexes
14+ import com.mongodb.client.model.MergeOptions
15+ import com.mongodb.client.model.MongoTimeUnit
16+ import com.mongodb.client.model.Projections
17+ import com.mongodb.client.model.Sorts
18+ import com.mongodb.client.model.UnwindOptions
19+ import com.mongodb.client.model.Variable
20+ import com.mongodb.client.model.WindowOutputFields
21+ import com.mongodb.client.model.Windows
722import com.mongodb.client.model.densify.DensifyOptions
823import com.mongodb.client.model.densify.DensifyRange
924import com.mongodb.client.model.fill.FillOptions
@@ -21,7 +36,10 @@ import kotlinx.coroutines.runBlocking
2136import org.bson.Document
2237import org.bson.codecs.pojo.annotations.BsonId
2338import org.bson.types.ObjectId
24- import org.junit.jupiter.api.*
39+ import org.junit.jupiter.api.AfterAll
40+ import org.junit.jupiter.api.BeforeAll
41+ import org.junit.jupiter.api.Test
42+ import org.junit.jupiter.api.TestInstance
2543import java.time.LocalDateTime
2644import kotlin.test.Ignore
2745import kotlin.test.assertEquals
@@ -116,8 +134,8 @@ class AggregatesBuilderTest {
116134 val collection = database.getCollection<Document >(" someCollection" )
117135 collection.insertOne(Document (" someField" , " someCriteria" ))
118136 // :snippet-start: methods-example
119- val matchStage = match(Filters .eq(" someField" , " someCriteria" ))
120- val sortByCountStage = sortByCount(" \$ someField" )
137+ val matchStage = Aggregates . match(Filters .eq(" someField" , " someCriteria" ))
138+ val sortByCountStage = Aggregates . sortByCount(" \$ someField" )
121139 val results = collection.aggregate(
122140 listOf (matchStage, sortByCountStage)).toList()
123141 // :snippet-end:
@@ -338,8 +356,8 @@ class AggregatesBuilderTest {
338356 val grouping = orderCollection.aggregate<Results >(listOf (
339357 // :snippet-start: group
340358 Aggregates .group(" \$ ${Order ::customerId.name} " ,
341- sum(" totalQuantity" , " \$ ${Order ::ordered.name} " ),
342- avg(" averageQuantity" , " \$ ${Order ::ordered.name} " )
359+ Accumulators . sum(" totalQuantity" , " \$ ${Order ::ordered.name} " ),
360+ Accumulators . avg(" averageQuantity" , " \$ ${Order ::ordered.name} " )
343361 )
344362 // :snippet-end:
345363 ))
@@ -673,7 +691,7 @@ class AggregatesBuilderTest {
673691
674692 val resultsFlow = translateCollection.aggregate<Results >(listOf (
675693 // :snippet-start: replace-root
676- replaceRoot(" \$ ${Book ::spanishTranslation.name} " )
694+ Aggregates . replaceRoot(" \$ ${Book ::spanishTranslation.name} " )
677695 // :snippet-end:
678696
679697 ))
@@ -686,7 +704,7 @@ class AggregatesBuilderTest {
686704 data class Results (val watched : Boolean , val type : String )
687705 val resultsFlow = movieCollection.aggregate<Results >(listOf (
688706 // :snippet-start: add-fields
689- addFields(
707+ Aggregates . addFields(
690708 Field (" watched" , false ),
691709 Field (" type" , " movie" )
692710 )
@@ -711,7 +729,7 @@ class AggregatesBuilderTest {
711729 fun bucketTest () = runBlocking {
712730 val resultsFlow = screenCollection.aggregate<Document >(listOf (
713731 // :snippet-start: bucket
714- bucket(" \$ ${Screen ::screenSize.name} " , listOf (0 , 24 , 32 , 50 , 70 , 1000 ))
732+ Aggregates . bucket(" \$ ${Screen ::screenSize.name} " , listOf (0 , 24 , 32 , 50 , 70 , 1000 ))
715733 // :snippet-end:
716734 ))
717735 assertEquals(4 , resultsFlow.toList().size)
@@ -722,12 +740,12 @@ class AggregatesBuilderTest {
722740 data class Results (val count : Int , val matches : List <Int >)
723741 val resultsFlow = screenCollection.aggregate<Results >(listOf (
724742 // :snippet-start: bucket-options
725- bucket(" \$ ${Screen ::screenSize.name} " , listOf (0 , 24 , 32 , 50 , 70 ),
743+ Aggregates . bucket(" \$ ${Screen ::screenSize.name} " , listOf (0 , 24 , 32 , 50 , 70 ),
726744 BucketOptions ()
727745 .defaultBucket(" monster" )
728746 .output(
729- sum(" count" , 1 ),
730- push(" matches" , " \$ ${Screen ::screenSize.name} " )
747+ Accumulators . sum(" count" , 1 ),
748+ Accumulators . push(" matches" , " \$ ${Screen ::screenSize.name} " )
731749 )
732750 )
733751 // :snippet-end:
@@ -741,7 +759,7 @@ class AggregatesBuilderTest {
741759 data class Results (@BsonId val id : MinMax , val count : Int )
742760 val resultsFlow = screenCollection.aggregate<Results >(listOf (
743761 // :snippet-start: bucket-auto
744- bucketAuto(" \$ ${Screen ::screenSize.name} " , 5 )
762+ Aggregates . bucketAuto(" \$ ${Screen ::screenSize.name} " , 5 )
745763 // :snippet-end:
746764 ))
747765 assertEquals(5 , resultsFlow.toList().size)
@@ -755,11 +773,11 @@ class AggregatesBuilderTest {
755773 // example kotlin nested data classes
756774 val resultsFlow = screenCollection.aggregate<Results >(listOf (
757775 // :snippet-start: bucket-auto-options
758- bucketAuto(
776+ Aggregates . bucketAuto(
759777 " \$ ${Screen ::price.name} " , 5 ,
760778 BucketAutoOptions ()
761779 .granularity(BucketGranularity .POWERSOF2 )
762- .output(sum(" count" , 1 ), avg(" avgPrice" , " \$ ${Screen ::price.name} " ))
780+ .output(Accumulators . sum(" count" , 1 ), Accumulators . avg(" avgPrice" , " \$ ${Screen ::price.name} " ))
763781 )
764782 // :snippet-end:
765783 ))
@@ -774,19 +792,19 @@ class AggregatesBuilderTest {
774792 data class Results (val `Screen Sizes `: List <ScreenSize >)
775793 val resultsFlow = screenCollection.aggregate<Results >(listOf (
776794 // :snippet-start: facet
777- facet(
795+ Aggregates . facet(
778796 Facet (
779797 " Screen Sizes" ,
780- bucketAuto(
798+ Aggregates . bucketAuto(
781799 " \$ ${Screen ::screenSize.name} " ,
782800 5 ,
783- BucketAutoOptions ().output(sum(" count" , 1 ))
801+ BucketAutoOptions ().output(Accumulators . sum(" count" , 1 ))
784802 )
785803 ),
786804 Facet (
787805 " Manufacturer" ,
788- sortByCount(" \$ ${Screen ::manufacturer.name} " ),
789- limit(5 )
806+ Aggregates . sortByCount(" \$ ${Screen ::manufacturer.name} " ),
807+ Aggregates . limit(5 )
790808 )
791809 )
792810 // :snippet-end:
@@ -852,7 +870,7 @@ class AggregatesBuilderTest {
852870 val resultsFlow = weatherCollection.aggregate<Weather >(
853871 listOf (
854872 Aggregates .fill(
855- FillOptions .fillOptions().sortBy(ascending(Weather ::hour.name)),
873+ FillOptions .fillOptions().sortBy(Sorts . ascending(Weather ::hour.name)),
856874 FillOutputField .value(Weather ::temperature.name, " 23.6C" ),
857875 FillOutputField .linear(Weather ::air_pressure.name)
858876 )
@@ -881,7 +899,7 @@ class AggregatesBuilderTest {
881899 weatherCollection.insertMany(weather)
882900 val resultsFlow = weatherCollection.aggregate<Document >(listOf (
883901 // :snippet-start: densify
884- densify(
902+ Aggregates . densify(
885903 " ts" ,
886904 DensifyRange .partitionRangeWithStep(15 , MongoTimeUnit .MINUTE ),
887905 DensifyOptions .densifyOptions().partitionByFields(" Position.coordinates" )
0 commit comments