Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.pathtoBsonPath

toBsonPath

fun Path.toBsonPath(): ERROR CLASS: Symbol not found for BsonPath

Converts this MongoDB Path to a BsonPath.

BsonPath is an implementation of RFC9535 JSONPath. See its documentation for more information.

fun Field<*, *>.toBsonPath(): ERROR CLASS: Symbol not found for BsonPath

Converts this MongoDB Field to a BsonPath.

BsonPath is an implementation of RFC9535 JSONPath. See its documentation for more information.

BsonPath can be useful to access elements from an arbitrary BSON document, for example, after a projection.

Example

data class User(
    val _id: ObjectId,
    val profile: Profile,
)

data class Profile(
    val name: String,
)

val fieldName = (User::profile / Profile::name).toBsonPath()

val bson: Bson = 
val name = bson at fieldName

See also

  • select Select multiple values.

  • selectFirst Select the first value.

  • at Select the first value, as an infix operator.