CLOVIS
11/20/2024, 11:27 PMusers.find {
User::pets / Pet::name eq "Bob"
}
As you can see, a DSL replaces the parenthesis, but the syntax is almost identical.
measurements.upsertOne(
filter = {
Measurement::room eq 5
Measurement::storey eq 2
},
update = {
Measurement::creationDate setOnInsert Instant.now()
Measurement::lastModifiedDate set Instant.now()
Measurement::value inc 12
}
)
The DSL vastly simplifies syntax: no need to remember to group update operators, no need to specify and
when multiple filters are specified—and we can finally use a regular if
inside requests to create complex queries without making the code complex itself.
Currently, KtMongo has released its 0.4.0 version. It isn't stable yet, and won't be for a while, but it is ready for feedback and early tests. Currently, it supports:
• insertOne, insertMany
• updateOne, updateMany, upsertOne
• bulkWrite
• find
• count
• drop
as well as the operators:
• $eq, $gt, $gte, $in, $lt, $lte, $ne, $and, $not, $or, $exists, $type, $all, $elemMatch
• $inc, $rename, $set, $setOnInsert, $unset, $.0.
Want to learn more reasons why to migrate when the library becomes stable? Visit our website. We plan on adding documentation pages on gradual migration (migrating from KMongo to KtMongo one-file-at-a-time, without a big-bang migration).
Join us to discuss the project in #C078Z1QRHL3 , we're excited to see how far we can push Kotlin and MongoDB!Marcin Wisniowski
02/14/2025, 10:25 AMCLOVIS
02/14/2025, 10:37 AM