A Kotlin toolkit for Mongo
Questions tagged [kmongo]
48 questions
0
votes
0 answers
MongoDB KMongo Infinite Recursion - Reference to Parent in OneToMany realtionship
I have two classes, the Artist, and the Album.
I would like to embed the Album in the Artist document, but keep a reference to the Artist, and also i want to have a collection with Album document.
Here's a simplified code which doesn't work, because…

Jakab Martin
- 23
- 6
0
votes
1 answer
Gradle + Kotest + KMongo Coroutines - Could not create instance of class
I'm writing a small application in Kotlin that uses KMongo coroutines and I want to use Kotest as the testing framework.
I wrote a simple test to access a database and retrieve a document:
class KabotMultiDBClientTest : StringSpec({
val client…

TestaDiRapa
- 53
- 1
- 3
0
votes
0 answers
kmongo connot save kotlinx-datetime objects
I am trying to use kmongo with kotlinx-datetime. The data class looks like this:
@Serializable
data class CustomerCount(
@Contextual val _id: Id?,
val counter: Int,
@Contextual val date: LocalDateTime
) {
…

Roger
- 75
- 7
0
votes
0 answers
Kmongo HowTo do sum aggregation for data inside a List
I seem to have a compounded error
The first Error is I do not know How to do the sum aggregation with my data classes, I guess the serialization
problem will go away once I have fixed it.
I have a Data Class(es)
data class MyClass(
val items:…

CryptoCode
- 945
- 6
- 19
0
votes
0 answers
Ktor+Koin: Why unit test still keep connect to mongodb even I mocked the service that injected with `CoroutineDatabase` instance
Note: I'm a Kotlin beginner
Developing stack
Ktor
Koin
KMongo: MongoDB
I defined my application to be like this
Route -> Service -> Repository
Route is define all HTTP request endpoints.
Service is business logic of application.
Repository is…

Natta Wang
- 553
- 11
- 18
0
votes
1 answer
coroutine not found for KMongo - kotlin backend with jwt
I am trying to implement kotlin backend with mongo DB and JWT, all requried dependencies are added as
ktor_version=2.1.0
kmongo_version=4.7.0
commons_codec_version=1.15
kotlin_version=1.6.21
logback_version=1.2.11
kotlin.code.style=official
But…

shehzy
- 2,215
- 3
- 25
- 45
0
votes
1 answer
Mongodb query returns null for nested queries (KMongo)
I'm new to ktor and am writing an application using it. I'm trying to add authors and their book titles and retrieve them from the database. My schema is given below.
(authors is my collection name)
authors = [
{
name: "Author1",
books: [{…

Anandakrishnan
- 347
- 1
- 4
- 18
0
votes
1 answer
uuidconfigurationexception in kmogo Kotlin
import org.litote.kmongo.KMongo
fun main() {
val client = Kmongo.createClient(/* connection string from mongodb */)
val database = client.getDatabase(/* databaseName */)
}
my code ^
this is what it returns:
Exception in thread "main"…

Rian-Tan
- 1
- 1
0
votes
1 answer
How to get items from collection by ids
I am passing a List that are item ids in a request. I need to get only items that ids are in a list. Basically, I send you a list of product ids and MongoDB should return a List. I thought it would be something built in, but I…

Kerubyte
- 27
- 6
0
votes
0 answers
MongoDB transaction making partial writes
I am using Kotlin, Kmongo and Ktor for my server app to manage MongoDB.
Here is one function that uses transactions:
var txnOptions: TransactionOptions = TransactionOptions.builder()
.readPreference(ReadPreference.primary())
…

Anudeep Ananth
- 955
- 1
- 8
- 30
0
votes
1 answer
How we can mock a CoroutineDatabase in ktor?
I use the KMongo tool
How we can mock a Coroutine Database?
How can we mock our database in a koin module?
Is there a way to do this?
Thanks for guiding me
Methods I have tried and it has not worked:
The first method:
single {
…

Vahid Garousi
- 546
- 4
- 17
0
votes
1 answer
Kmongo: how to add unique field
I have a simple user data class that looks like:
@Serializable
data class User(
@SerialName("_id")
val _id: Id = newId(),
val email: String,
var password: String,
var tokens: Array = arrayOf()
)
And I'd like the email value to be…

L. Blommers
- 83
- 6
0
votes
0 answers
KMongo creates multiple connections
I started working on a KMongo project in Kotlin, though when I connect to my database KMongo creates 2 connections, instead of one (look at the image here). Does somebody know why?
My class to connect with the database
object Mongo {
lateinit…

Marian
- 44
- 1
- 7
0
votes
1 answer
How do I save an image into a mongoDB collection using Kmongo?
I searched a lot today but all answers seem to be only in nodejs. I'm currently working on ktor application and I can't seem to find any way to upload images into MongoDB with KMongo.

Astro
- 376
- 5
- 11
0
votes
1 answer
Kotlin Kmongo library with abstract class collection
I have these models
abstract class Message : Data
data class TextMessage(val m: String): Message
data class ImageMessage(val m: ByteArray): Message
and I want to get a collection by the abstract class Message
database.getCollection
But it…

user16799920
- 27
- 5