Skip to content

Commit 19278b9

Browse files
committed
wip
1 parent 6fef9d5 commit 19278b9

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

source/migrate-kmongo.txt

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ operations.
159159
using infix notation:
160160

161161
.. code-block:: kotlin
162+
163+
import com.mongodb.kotlin.client.model.Filters.eq
164+
import com.mongodb.kotlin.client.model.Filters.lt
165+
import com.mongodb.kotlin.client.model.Updates.set
162166

163167
data class Jedi(val name: String, val age: Int)
164168

@@ -239,20 +243,20 @@ Both drivers provide support for type-safe queries using property references.
239243

240244
.. code-block:: kotlin
241245

242-
data class Person(val name: String, val email: String, val gender: String, val age: Int)
243-
data class Results(val email: String)
244-
245-
val collection = database.getCollection<Person>("people")
246-
247-
// Using Builders
248-
val filter = and(eq("gender", "female"), gt("age", 29))
249-
val projection = fields(excludeId(), include("email"))
250-
val results = collection.find<Results>(filter).projection(projection)
251-
252-
// Using Document class
253-
val filter = Document().append("gender", "female").append("age", Document().append("\$gt", 29))
254-
val projection = Document().append("_id", 0).append("email", 1)
255-
val results = collection.find<Results>(filter).projection(projection)
246+
data class Person(val name: String, val email: String, val gender: String, val age: Int)
247+
data class Results(val email: String)
248+
249+
val collection = database.getCollection<Person>("people")
250+
251+
// Using Builders
252+
val filter = and(eq("gender", "female"), gt("age", 29))
253+
val projection = fields(excludeId(), include("email"))
254+
val results = collection.find<Results>(filter).projection(projection)
255+
256+
// Using Document class
257+
val filter = Document().append("gender", "female").append("age", Document().append("\$gt", 29))
258+
val projection = Document().append("_id", 0).append("email", 1)
259+
val results = collection.find<Results>(filter).projection(projection)
256260

257261
To map a KMongo string query to the {+driver-short+}, you can use the ``JsonObject`` class.
258262

@@ -277,17 +281,23 @@ Both drivers provide support for type-safe queries using property references.
277281

278282
.. code-block:: kotlin
279283

280-
data class Person(val name: String, val gender: String, val age: Int)
281-
data class Result(val name: String)
284+
import com.mongodb.kotlin.client.model.Filters.eq
285+
import com.mongodb.kotlin.client.model.Filters.and
286+
import com.mongodb.kotlin.client.model.Filters.gt
287+
import com.mongodb.kotlin.client.model.Projections.excludeId
288+
import com.mongodb.kotlin.client.model.Projections.fields
289+
import com.mongodb.kotlin.client.model.Projections.include
282290

283-
val collection = database.getCollection<Person>("people")
291+
data class Person(val name: String, val gender: String, val age: Int)
292+
data class Result(val name: String)
284293

285-
// Infix Notation Query
286-
val filter = (Person::gender eq "female") and (Person::age gt 29))
287-
val projection = fields(excludeId(), include(Person::name))
288-
289-
val results = collection.find<Result>(filter).projection(projection)
290-
294+
val collection = database.getCollection<Person>("people")
295+
296+
// Infix Notation Query
297+
val filter = (Person::gender eq "female") and (Person::age gt 29))
298+
val projection = fields(excludeId(), include(Person::name))
299+
300+
val results = collection.find<Result>(filter).projection(projection)
291301

292302
To learn more and view examples that use all of the builder
293303
classes, see the :ref:`kotlin-builders-data-classes` guide.
@@ -500,7 +510,7 @@ Both drivers support synchronous and asynchronous operations.
500510
val collection = database.getCollection<Jedi>("jedi")
501511

502512
// Synchronous operations
503-
val jedi =a Jedi("Luke Skywalker", 19)
513+
val jedi = Jedi("Luke Skywalker", 19)
504514
collection.insertOne(jedi)
505515

506516
To write asynchronous coroutine code:
@@ -519,7 +529,7 @@ Both drivers support synchronous and asynchronous operations.
519529
runBlocking {
520530

521531
// Async operations
522-
val jedi =a Jedi("Luke Skywalker", 19)
532+
val jedi = Jedi("Luke Skywalker", 19)
523533
collection.insertOne(jedi)
524534
}
525535

0 commit comments

Comments
 (0)