toBsonPath

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

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(source)

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 multiple values.

Select the first value.

Select the first value, as an infix operator.