Help using kmongo "/" operator for querying nested properties

129 views
Skip to first unread message

Mark Lapasa

unread,
Jul 25, 2020, 11:34:31 PM7/25/20
to kmongo
Hi all,

I am trying to query the values of a nested document and in the documentation for querying nested properties (https://litote.org/kmongo/typed-queries/), I see the following code sample listed:

class Friend(val coor: Coordinate?) class Coordinate(val lat: Int, val lng : Int) 
// the generated query is {"coor.lat":{$lt:0}} col.findOne(Friend::coor / Coordinate::lat lt 0)  

Regarding, the "/" operator between "coor" and "Coordinate", what is the import statement that will allow IntelliJ IDE to auto complete this?

I am getting a red squiggly line with an autofix suggestion to create a new extension for 'div' or on my update.

This is what I am trying to do:

fun appendData(person: Person, data: Data) {

collection.updateOne(
            Snapshot::person / Person::_id eq targetPerson._id(),
            addToSet(Snapshot::data, data)
        )
}

TIA

Yuval Sapir

unread,
Jul 26, 2020, 9:45:15 AM7/26/20
to kmongo
Hi Mark.
I believe it's defined as a function in the org.litole.kmongo package.
Did you try
import org.litote.kmongo.*

Yuval

Mark Lapasa

unread,
Jul 27, 2020, 2:45:15 PM7/27/20
to kmongo
Thx Yuval for the response. Yep, I believe I got it working by putting together the following basic example:

import org.litote.kmongo.*

class Friend(val coor: Coordinate?)
class Coordinate(val lat: Int, val lng : Int)

class FriendDB {
    private val collection = KMongo.createClient().getDatabase("test").getCollection<Friend>()

    fun getByLat(lat: Int) {
        collection.findOne(Friend::coor / Coordinate::lat lt 0)
    }
}

Reply all
Reply to author
Forward
0 new messages