Skip to content

Commit 29befdb

Browse files
committed
eg
1 parent d0b3027 commit 29befdb

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

source/aggregation.txt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -215,29 +215,11 @@ You can build a Atlas Search pipeline stage using search operators.
215215

216216
.. io-code-block::
217217

218-
.. input::
218+
.. input:: /includes/aggregation/aggregation.kt
219219
:language: kotlin
220-
221-
val searchStage: Bson = Aggregates.search(
222-
SearchOperator.compound()
223-
.filter(
224-
listOf(
225-
SearchOperator.text(fieldPath("genres"), "Drama"),
226-
SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"),
227-
SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989),
228-
SearchOperator.wildcard(fieldPath("title"), "Rocky *")
229-
)
230-
)
231-
)
232-
233-
val projection = Projections.fields(
234-
Projections.include("title", "year", "genres", "cast")
235-
)
236-
237-
val aggregatePipelineStages: List<Bson> = listOf(searchStage, Aggregates.project(projection))
238-
val results = collection.aggregate<Document>(aggregatePipelineStages)
239-
240-
results.forEach { result -> println(result) }
220+
:start-after: // start-atlas-searchoperator-helpers
221+
:end-before: // end-atlas-searchoperator-helpers
222+
:dedent:
241223

242224
.. output::
243225
:language: console

source/includes/aggregation/aggregation.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,28 @@ fun main() {
4242
// start-aggregation-explain
4343
print(collection.aggregate(pipeline).explain())
4444
// end-aggregation-explain
45+
46+
// start-atlas-searchoperator-helpers
47+
val searchStage: Bson = Aggregates.search(
48+
SearchOperator.compound()
49+
.filter(
50+
listOf(
51+
SearchOperator.text(fieldPath("genres"), "Drama"),
52+
SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"),
53+
SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989),
54+
SearchOperator.wildcard(fieldPath("title"), "Rocky *")
55+
)
56+
)
57+
)
58+
59+
val projection = Projections.fields(
60+
Projections.include("title", "year", "genres", "cast")
61+
)
62+
63+
val aggregatePipelineStages: List<Bson> = listOf(searchStage, Aggregates.project(projection))
64+
val results = collection.aggregate<Document>(aggregatePipelineStages)
65+
66+
results.forEach { result -> println(result) }
67+
// end-atlas-searchoperator-helpers
4568
}
4669

0 commit comments

Comments
 (0)