Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.pathFieldCompanionunsafe

unsafe

fun <T> unsafe(child: String): Field<Any, T>

Refers to a field child with no compile-time safety.

Sometimes, we must refer to a field that we don't want to add in the DTO representation. For example, when writing complex aggregation queries that use intermediary fields that are removed before the data is sent to the server.

We recommend preferring the type-safe syntax when possible (see Field).

Example

println(Field.unsafe<Int>("age")) // 'age'

See also

  • Field.unsafe Similar, but for accessing a child of a document.