Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryUpdateQuerysetToCurrentDate

setToCurrentDate

abstract fun Field<T, ?>.setToCurrentDate()

Sets this field to the current date.

If the field does not exist, this operator adds the field to the document.

Example

class User(
    val name: String?,
    val age: Int,
    val modificationDate: Instant,
)

collection.filter {
    User::name eq "Bob"
}.updateMany {
    User::age set 18
    User::modificationDate.setToCurrentDate()
}

External resources

open fun KProperty1<T, ?>.setToCurrentDate()

Sets this field to the current date.

If the field does not exist, this operator adds the field to the document.

Example

class User(
    val name: String?,
    val age: Int,
    val modificationDate: Instant,
)

collection.filter {
    User::name eq "Bob"
}.updateMany {
    User::age set 18
    User::modificationDate.setToCurrentDate()
}

External resources

abstract fun Field<T, ?>.setToCurrentDate()

Sets this field to the current timestamp.

If the field does not exist, this operator adds the field to the document.

The time Timestamp is internal. Instant should be preferred. For more information, see Timestamp.

Example

class User(
    val name: String?,
    val age: Int,
    val modificationDate: Timestamp,
)

collection.filter {
    User::name eq "Bob"
}.updateMany {
    User::age set 18
    User::modificationDate.setToCurrentDate()
}

External resources

open fun KProperty1<T, ?>.setToCurrentDate()

Sets this field to the current timestamp.

If the field does not exist, this operator adds the field to the document.

The time Timestamp is internal. Instant should be preferred. For more information, see Timestamp.

Example

class User(
    val name: String?,
    val age: Int,
    val modificationDate: Timestamp,
)

collection.filter {
    User::name eq "Bob"
}.updateMany {
    User::age set 18
    User::modificationDate.setToCurrentDate()
}

External resources