# exposed


01/26/2023, 5:08 PM
Hello everyone, I am currently working on a full-stack web app using the tutorial found here: We have been using MongoDB and KMongo, but I am trying to replace MongoDB with Postgres DB and Kmongo with Exposed. As an example, using Kmongo, we have this code: val client = KMongo.createClient().coroutine val database = client.getDatabase("shoppingList") val collection = database.getCollection<ShoppingListItem>() get { call.respond(collection.find().toList()) } I am wondering if there is a way to do the same thing with Exposed. My current understanding is to create an object DatabaseFactory for setup in Server.kt, create a Table and then use select:
object DatabaseFactory {
fun init() {
driver = "org.postgresql.Driver",
user = "user",
password = "password"
object ShoppingListItems: Table() {
val id = integer("id").autoIncrement().primaryKey()
val name = varchar("name", length = 255)
val owners = varchar("owners", length = 255)
get {
call.respond( { ShoppingListItems.owners like user }.toList())
I am also wondering if we need to create a table. Instead, I want to use a data class like this: val collection = database.getCollection<ShoppingListItem>(). Thank you in advance for your help!