Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.aggregation.operatorsArrayValueOperatorsaverage

average

Returns the average of the elements in the array.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
    val averageScore: Double,
)

players.updateManyWithPipeline {
    set {
        Player::averageScore set Player::scores.average()
    }
}

External resources

Returns the average of the elements in the array.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
    val averageScore: Double,
)

players.updateManyWithPipeline {
    set {
        Player::averageScore set Player::scores.average()
    }
}

External resources

Returns the average of the elements in the array.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
    val averageScore: Double,
)

players.updateManyWithPipeline {
    set {
        Player::averageScore set Player::scores.average()
    }
}

External resources

Returns the average of the elements in the array.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
    val averageScore: Double,
)

players.updateManyWithPipeline {
    set {
        Player::averageScore set Player::scores.average()
    }
}

External resources

open fun <Context : Any, T : Number> average(vararg input: Value<Context, Number?>): Value<Context, T>

Returns the average of the elements in the array.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
    val averageScore: Double,
)

players.updateManyWithPipeline {
    set {
        Player::averageScore set Player::scores.average()
    }
}

External resources

open fun <Context : Any, T : Number> average(): Value<Context, T>

Deprecated (with error)

Computing the average of 0 elements makes no sense, you should specify the elements to average as the receiver or as arguments.