Database is not created on MongoDB

68 views
Skip to first unread message

Solomon Tolu Samuel

unread,
Jul 22, 2021, 5:53:37 AM7/22/21
to kmongo
Hello, please i am completely lost and i need help with connecting a mongodb to my ktor application

This is the code i have, as followed from this article: https://himanshoe.com/mongodb-in-ktor

class MongoDataHandler {

val client = KMongo.createClient().coroutine
val database = client.getDatabase("dev")
val userCollection = database.getCollection<User>()

suspend fun adduser(email: String, username: String, password: String): User? {
userCollection.insertOne(User(userId = null, email = email, userName = username, passwordHash = password))
return userCollection.findOne(User::email eq email )
}
suspend fun finduser(id: String): User?{
return userCollection.findOneById(id)
}
}
I installed mongodb as directed from their website and the mongodb is started as a service upon successful install. I run this command  "C:\Program Files\MongoDB\Server\5.0\bin\mongo.exe" to use the mongodb. When i check for the available database "dev" is never listed.

I guess i am doing something wrong... thanks in advance
Reply all
Reply to author
Forward
0 new messages