Skip to content

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

select

inline fun <T> Bson.select(path: BsonPath): Sequence<T>

Finds all values that match path in a given BSON document.

Example

val document: Bson = 

document.select<String>(BsonPath["foo"]["bar"]).firstOrNull()

will return the value of the field foo.bar.

See also

  • BsonPath Learn more about BSON paths.

  • selectFirst If you're only interested about a single element. See also at.

inline fun <T> Bson.select(@Language
(value = "JSONPath") path: String): Sequence<T>

Finds all values that match path in a given BSON document.

To learn more about the syntax, see BsonPath.

Example

val document: Bson = 

document.select<String>("$.foo.bar")

will return a sequence of all values matching the path foo.bar.

See also

  • at Select a single value.