Skip to content

Kotlin BSON • Multiplatform abstraction for different BSON implementationsopensavvy.ktmongo.bsonBsonPathRootparse

parse

fun parse(@Language
(value = "JSONPath") text: String): BsonPath

Parses an RFC-9535 compliant string expression into a BsonPath instance.

This function is the mirror of the BsonPath.toString methods.

Warning. Not everything from the RFC is implemented at the moment. As a rule of thumb, if text can be returned by the BsonPath.toString function of a segment, then it can be parsed by this function.

Examples

val document: Bson = 

val id: Uuid = document at BsonPath.parse("$.profile.id")

for (user in document.select<User>("$.friends")) {
    println("User: $user")
}

See also

  • BsonPath Learn more about BSON paths.

  • at Access one field by its BSON path.

  • select Access multiple fields by their BSON path.