Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.pathFieldDslunsafe

unsafe

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: String): Field<Root, Child>

Refers to a field child of the current field, 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(User::profile.unsafe<Int>("age")) // 'profile.age'

See also

open infix fun <Root, Child> Field<Root, *>.unsafe(child: Field<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

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

Example

println(User::profile / Pet::name)       // ⚠ compilation error: 'profile' doesn't have the type 'Pet'
println(User::profile unsafe Pet::name)  // 'profile.name'

See also

open infix fun <Root, Child> Field<Root, *>.unsafe(child: KProperty1<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

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

Example

println(User::profile / Pet::name)       // ⚠ compilation error: 'profile' doesn't have the type 'Pet'
println(User::profile unsafe Pet::name)  // 'profile.name'

See also

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: Field<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

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

Example

println(User::profile / Pet::name)       // ⚠ compilation error: 'profile' doesn't have the type 'Pet'
println(User::profile unsafe Pet::name)  // 'profile.name'

See also

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: KProperty1<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

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

Example

println(User::profile / Pet::name)       // ⚠ compilation error: 'profile' doesn't have the type 'Pet'
println(User::profile unsafe Pet::name)  // 'profile.name'

See also