Skip to content

selectFirst

inline fun <T> Bson.selectFirst(field: Field<*, T>): T

Finds the first value that matches field in a given BSON document.

To learn more about the syntax, see BsonPath.

Example

val document: Bson = 

document.selectFirst(User::profile / Profile::name)

will return the value of the field profile.name.

See also

  • BsonPath: Learn more about BSON paths.

  • select: Select multiple values with a BSON path.

  • at: Select a single value using infix notation.

Throws

NoSuchElementException

If no element is found matching the path.