Litote / kmongo

[deprecated] KMongo - a Kotlin toolkit for Mongo
https://litote.org/kmongo/
Apache License 2.0
781 stars 74 forks source link

Trying to debug typed queries throws kotlinx.serialization.SerializationException: Serializer for class 'CoroutineFindPublisher' is not found. #350

Closed k-arabadzhiev closed 2 years ago

k-arabadzhiev commented 2 years ago

Probably I'm using it wrong, I'm new to both mongo and kmongo. I'm trying to debug my query:

val query = users.find(
    Roommate::id ne ObjectId(id),
    Roommate::age gte ageMin,
    Roommate::age lte ageMax,
    Roommate::hasRoom ne hasRoom,
    Roommate::budget gte budget - 50,
    Roommate::budget lte budget + 50,
    Roommate::city / City::name eq city,
    Roommate::gender `in` searchFor,
    Roommate::interestedIn contains gender
).skip(skip = (page - 1) * limit).limit(limit).partial(true)
println(query.json)

However, the print line will throw the exception. Otherwise it works perfectly fine.

zigzago commented 2 years ago

Use toList() as specified here: https://litote.org/kmongo/extensions-overview/#find

Then you can print the list ;)

HTH

k-arabadzhiev commented 2 years ago

This will print the result of the query as a list. It works as expected, however I'm trying to print the json version of the query as shown here https://litote.org/kmongo/typed-queries/#debugging-typed-queries

zigzago commented 2 years ago

Ok, then you can write something like:

val q = and(
    Roommate::id ne ObjectId(id),
    Roommate::age gte ageMin,
    Roommate::age lte ageMax,
    Roommate::hasRoom ne hasRoom,
    Roommate::budget gte budget - 50,
    Roommate::budget lte budget + 50,
    Roommate::city / City::name eq city,
    Roommate::gender `in` searchFor,
    Roommate::interestedIn contains gender
)
println(q.json)
val query = users.find(q).skip(skip = (page - 1) * limit).limit(limit).partial(true)

HTH

k-arabadzhiev commented 2 years ago

That works, thanks! Sorry for opening an issue for such a minor thing, I found about the google group later, I guess it would've been better to ask there.